refactored android example_app
This commit is contained in:
@@ -23,13 +23,14 @@ In this example we aim to set up a minimal [Android Studio](https://developer.an
|
||||
|
||||
```
|
||||
package ZeroTierSDK;
|
||||
public class ZeroTierSDK_Wrapper {
|
||||
public class ZeroTierSDK {
|
||||
public native void startOneService();
|
||||
static { System.loadLibrary("ZeroTierOneJNI"); } // Loads JNI code
|
||||
}
|
||||
```
|
||||
|
||||
- And now, start the service:
|
||||
|
||||
```
|
||||
new Thread(new Runnable() {
|
||||
public void run() {
|
||||
@@ -55,3 +56,11 @@ new Thread(new Runnable() {
|
||||
**Step 6: Join a network!**
|
||||
|
||||
- Simply call `zt_join_network("XXXXXXXXXXXXXXXX")`
|
||||
|
||||
|
||||
|
||||
***
|
||||
|
||||
*Note for the curious on JNI naming conventions: In order to reference a symbol in the JNI library you need to structure the package and class in your Android Studio project in a very particular way. For example, in the ZeroTierSDK we define a function called `Java_ZeroTier_SDK_startOneService`, the name can be broken down as follows: `Java_PACKAGENAME_CLASSNAME_startOneService`, so as we've defined it, you must create a package called `ZeroTier` and add a class called `SDK`.*
|
||||
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ android {
|
||||
compileSdkVersion 23
|
||||
buildToolsVersion "23.0.3"
|
||||
defaultConfig {
|
||||
applicationId "com.example.joseph.example_android_app"
|
||||
applicationId "com.example.joseph.example_app"
|
||||
minSdkVersion 15
|
||||
targetSdkVersion 23
|
||||
versionCode 1
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.example.joseph.example_android_app;
|
||||
package com.example.joseph.example_app;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.test.InstrumentationRegistry;
|
||||
@@ -24,6 +24,6 @@ public class ExampleInstrumentationTest {
|
||||
// Context of the app under test.
|
||||
Context appContext = InstrumentationRegistry.getTargetContext();
|
||||
|
||||
assertEquals("com.example.joseph.example_android_app", appContext.getPackageName());
|
||||
assertEquals("com.example.joseph.example_app", appContext.getPackageName());
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.example.joseph.example_android_app">
|
||||
package="com.example.joseph.example_app">
|
||||
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
@@ -8,10 +8,6 @@
|
||||
android:label="@string/app_name"
|
||||
android:supportsRtl="true"
|
||||
android:theme="@style/AppTheme">
|
||||
|
||||
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
||||
|
||||
<activity android:name=".MainActivity">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
package ZeroTierSDK.ZeroTierSDK;
|
||||
public class ZeroTierSDK {
|
||||
package SDK;
|
||||
public class SDK {
|
||||
public native void startOneService();
|
||||
static { System.loadLibrary("ZeroTierOneJNI"); } // Loads JNI code
|
||||
}
|
||||
@@ -1,8 +1,10 @@
|
||||
package com.example.joseph.example_android_app;
|
||||
package com.example.joseph.example_app;
|
||||
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.os.Bundle;
|
||||
|
||||
import SDK.SDK;
|
||||
|
||||
public class MainActivity extends AppCompatActivity {
|
||||
|
||||
@Override
|
||||
@@ -12,10 +14,9 @@ public class MainActivity extends AppCompatActivity {
|
||||
|
||||
new Thread(new Runnable() {
|
||||
public void run() {
|
||||
ZeroTierSDK wrapper = new ZeroTierSDK();
|
||||
SDK wrapper = new SDK();
|
||||
wrapper.startOneService(); // Calls to JNI code
|
||||
}
|
||||
}).start();
|
||||
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,7 @@
|
||||
android:id="@+id/activity_main"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:context="com.example.joseph.example_android_app.MainActivity">
|
||||
tools:context="com.example.joseph.example_app.MainActivity">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
<resources>
|
||||
<string name="app_name">Example_Android_App</string>
|
||||
<string name="app_name">example_app</string>
|
||||
</resources>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.example.joseph.example_android_app;
|
||||
package com.example.joseph.example_app;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
@@ -11,9 +11,6 @@
|
||||
# The setting is particularly useful for tweaking memory settings.
|
||||
org.gradle.jvmargs=-Xmx1536m
|
||||
|
||||
org.gradle.daemon=true
|
||||
org.gradle.parallel=true
|
||||
|
||||
# When configured, Gradle will run in incubating parallel mode.
|
||||
# This option should only be used with decoupled projects. More details, visit
|
||||
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
|
||||
|
||||
Binary file not shown.
13
make-mac.mk
13
make-mac.mk
@@ -72,9 +72,11 @@ ios_unity3d_bundle:
|
||||
# Build JNI library for Android app integration
|
||||
android_jni_lib:
|
||||
cd integrations/android/android_jni_lib/proj; ./gradlew assembleDebug
|
||||
# cd integrations/android/android_jni_lib/java/libs/; for f in *; do mv "$f" "android_jni_lib_$f"; done
|
||||
# copy binary into example android project dir
|
||||
cp integrations/android/android_jni_lib/java/libs/* build
|
||||
mv integrations/android/android_jni_lib/java/libs/* build
|
||||
cp docs/android_zt_sdk.md build/README.md
|
||||
cd build; for res_f in *; do mv "$res_f" "android_jni_lib_$res_f"; done
|
||||
#cp docs/android_zt_sdk.md build/README.md
|
||||
|
||||
osx_shared_lib: $(OBJS)
|
||||
rm -f *.o
|
||||
@@ -90,6 +92,10 @@ osx_shared_lib: $(OBJS)
|
||||
ln -sf zerotier-sdk-service zerotier-idtool
|
||||
cp docs/osx_zt_sdk.md build/osx_shared_lib/README.md
|
||||
|
||||
|
||||
prep:
|
||||
cp integrations/android/android_jni_lib/java/libs/* build
|
||||
|
||||
check:
|
||||
./check.sh build/lwip/liblwip.so
|
||||
|
||||
@@ -113,6 +119,9 @@ check:
|
||||
./check.sh build/
|
||||
./check.sh build/
|
||||
|
||||
selftest:
|
||||
|
||||
|
||||
clean:
|
||||
rm -rf zerotier-cli zerotier-idtool
|
||||
|
||||
|
||||
@@ -40,7 +40,7 @@ extern "C" {
|
||||
#define INTERCEPT_DISABLED 222
|
||||
|
||||
#if defined(__ANDROID__)
|
||||
JNIEXPORT void JNICALL Java_ZeroTierSDK_startOneService(JNIEnv *env, jobject thisObj);
|
||||
JNIEXPORT void JNICALL Java_ZeroTier_SDK_startOneService(JNIEnv *env, jobject thisObj);
|
||||
#else
|
||||
void *startOneService(void *thread_id);
|
||||
void init_service(int key, const char * path);
|
||||
|
||||
Reference in New Issue
Block a user