diff --git a/Examples/android/extend/AndroidManifest.xml b/Examples/android/extend/AndroidManifest.xml new file mode 100644 index 000000000..66d2469fa --- /dev/null +++ b/Examples/android/extend/AndroidManifest.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + diff --git a/Examples/android/extend/Makefile b/Examples/android/extend/Makefile new file mode 100644 index 000000000..98a0372dd --- /dev/null +++ b/Examples/android/extend/Makefile @@ -0,0 +1,29 @@ +TOP = ../.. +SWIG = $(TOP)/../preinst-swig +TARGET = example +INTERFACE = example.i +PACKAGEDIR = src/org/swig +PACKAGENAME= org.swig.extendexample +SWIGOPT = -package $(PACKAGENAME) -outdir $(PACKAGEDIR)/extendexample +PROJECTNAME= SwigExtend +TARGETID = 1 + +all:: android + +android:: + android update project --target $(TARGETID) --name $(PROJECTNAME) --path . + $(SWIG) -c++ -java $(SWIGOPT) -o jni/$(TARGET)_wrap.cpp jni/$(INTERFACE) + ndk-build + ant debug + +install:: + -adb uninstall $(PACKAGENAME) + adb install bin/$(PROJECTNAME)-debug.apk + +clean:: + ant clean + rm -f jni/$(TARGET)_wrap.cpp + rm -f `find $(PACKAGEDIR) -name \*.java | grep -v $(PROJECTNAME).java` + + +check: all diff --git a/Examples/android/extend/ant.properties b/Examples/android/extend/ant.properties new file mode 100644 index 000000000..ee52d86d9 --- /dev/null +++ b/Examples/android/extend/ant.properties @@ -0,0 +1,17 @@ +# This file is used to override default values used by the Ant build system. +# +# This file must be checked in Version Control Systems, as it is +# integral to the build system of your project. + +# This file is only used by the Ant script. + +# You can use this to override default values such as +# 'source.dir' for the location of your java source folder and +# 'out.dir' for the location of your output folder. + +# You can also use it define how the release builds are signed by declaring +# the following properties: +# 'key.store' for the location of your keystore and +# 'key.alias' for the name of the key to use. +# The password will be asked during the build when you use the 'release' target. + diff --git a/Examples/android/extend/build.xml b/Examples/android/extend/build.xml new file mode 100644 index 000000000..94fe847b7 --- /dev/null +++ b/Examples/android/extend/build.xml @@ -0,0 +1,85 @@ + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Examples/android/extend/jni/Android.mk b/Examples/android/extend/jni/Android.mk new file mode 100644 index 000000000..25d42b541 --- /dev/null +++ b/Examples/android/extend/jni/Android.mk @@ -0,0 +1,10 @@ +# File: Android.mk +LOCAL_PATH := $(call my-dir) + +include $(CLEAR_VARS) + +LOCAL_MODULE := example +LOCAL_SRC_FILES := example_wrap.cpp example.cpp +LOCAL_CFLAGS := -frtti + +include $(BUILD_SHARED_LIBRARY) diff --git a/Examples/android/extend/jni/Application.mk b/Examples/android/extend/jni/Application.mk new file mode 100644 index 000000000..87124dd88 --- /dev/null +++ b/Examples/android/extend/jni/Application.mk @@ -0,0 +1 @@ +APP_STL := gnustl_static diff --git a/Examples/android/extend/jni/example.cpp b/Examples/android/extend/jni/example.cpp new file mode 100644 index 000000000..450d75608 --- /dev/null +++ b/Examples/android/extend/jni/example.cpp @@ -0,0 +1,4 @@ +/* File : example.cxx */ + +#include "example.h" + diff --git a/Examples/android/extend/jni/example.h b/Examples/android/extend/jni/example.h new file mode 100644 index 000000000..b27ab9711 --- /dev/null +++ b/Examples/android/extend/jni/example.h @@ -0,0 +1,56 @@ +/* File : example.h */ + +#include +#include +#include +#include +#include + +class Employee { +private: + std::string name; +public: + Employee(const char* n): name(n) {} + virtual std::string getTitle() { return getPosition() + " " + getName(); } + virtual std::string getName() { return name; } + virtual std::string getPosition() const { return "Employee"; } + virtual ~Employee() { printf("~Employee() @ %p\n", this); } +}; + + +class Manager: public Employee { +public: + Manager(const char* n): Employee(n) {} + virtual std::string getPosition() const { return "Manager"; } +}; + + +class EmployeeList { + std::vector list; +public: + EmployeeList() { + list.push_back(new Employee("Bob")); + list.push_back(new Employee("Jane")); + list.push_back(new Manager("Ted")); + } + void addEmployee(Employee *p) { + list.push_back(p); + std::cout << "New employee added. Current employees are:" << std::endl; + std::vector::iterator i; + for (i=list.begin(); i!=list.end(); i++) { + std::cout << " " << (*i)->getTitle() << std::endl; + } + } + const Employee *get_item(int i) { + return list[i]; + } + ~EmployeeList() { + std::vector::iterator i; + std::cout << "~EmployeeList, deleting " << list.size() << " employees." << std::endl; + for (i=list.begin(); i!=list.end(); i++) { + delete *i; + } + std::cout << "~EmployeeList empty." << std::endl; + } +}; + diff --git a/Examples/android/extend/jni/example.i b/Examples/android/extend/jni/example.i new file mode 100644 index 000000000..c8ec32e09 --- /dev/null +++ b/Examples/android/extend/jni/example.i @@ -0,0 +1,15 @@ +/* File : example.i */ +%module(directors="1") example +%{ +#include "example.h" +%} + +%include "std_vector.i" +%include "std_string.i" + +/* turn on director wrapping for Manager */ +%feature("director") Employee; +%feature("director") Manager; + +%include "example.h" + diff --git a/Examples/android/extend/local.properties b/Examples/android/extend/local.properties new file mode 100644 index 000000000..14b8d63b4 --- /dev/null +++ b/Examples/android/extend/local.properties @@ -0,0 +1,10 @@ +# This file is automatically generated by Android Tools. +# Do not modify this file -- YOUR CHANGES WILL BE ERASED! +# +# This file must *NOT* be checked in Version Control Systems, +# as it contains information specific to your local configuration. + +# location of the SDK. This is only used by Ant +# For customization when using a Version Control System, please read the +# header note. +sdk.dir=/home/william/android/android-sdk-linux_x86 diff --git a/Examples/android/extend/proguard.cfg b/Examples/android/extend/proguard.cfg new file mode 100644 index 000000000..b1cdf17b5 --- /dev/null +++ b/Examples/android/extend/proguard.cfg @@ -0,0 +1,40 @@ +-optimizationpasses 5 +-dontusemixedcaseclassnames +-dontskipnonpubliclibraryclasses +-dontpreverify +-verbose +-optimizations !code/simplification/arithmetic,!field/*,!class/merging/* + +-keep public class * extends android.app.Activity +-keep public class * extends android.app.Application +-keep public class * extends android.app.Service +-keep public class * extends android.content.BroadcastReceiver +-keep public class * extends android.content.ContentProvider +-keep public class * extends android.app.backup.BackupAgentHelper +-keep public class * extends android.preference.Preference +-keep public class com.android.vending.licensing.ILicensingService + +-keepclasseswithmembernames class * { + native ; +} + +-keepclasseswithmembers class * { + public (android.content.Context, android.util.AttributeSet); +} + +-keepclasseswithmembers class * { + public (android.content.Context, android.util.AttributeSet, int); +} + +-keepclassmembers class * extends android.app.Activity { + public void *(android.view.View); +} + +-keepclassmembers enum * { + public static **[] values(); + public static ** valueOf(java.lang.String); +} + +-keep class * implements android.os.Parcelable { + public static final android.os.Parcelable$Creator *; +} diff --git a/Examples/android/extend/project.properties b/Examples/android/extend/project.properties new file mode 100644 index 000000000..ea89160e0 --- /dev/null +++ b/Examples/android/extend/project.properties @@ -0,0 +1,11 @@ +# This file is automatically generated by Android Tools. +# Do not modify this file -- YOUR CHANGES WILL BE ERASED! +# +# This file must be checked in Version Control Systems. +# +# To customize properties used by the Ant build system use, +# "ant.properties", and override values to adapt the script to your +# project structure. + +# Project target. +target=android-8 diff --git a/Examples/android/extend/res/layout/main.xml b/Examples/android/extend/res/layout/main.xml new file mode 100644 index 000000000..d4e5d7fe8 --- /dev/null +++ b/Examples/android/extend/res/layout/main.xml @@ -0,0 +1,25 @@ + + +