Android: Move native code to its own class

This commit is contained in:
Vishesh Handa
2019-05-14 13:13:30 +02:00
parent cd68df9303
commit 668eae3562
3 changed files with 17 additions and 14 deletions

View File

@ -8,7 +8,7 @@
#include <git2.h> #include <git2.h>
extern "C" JNIEXPORT jstring JNICALL extern "C" JNIEXPORT jstring JNICALL
Java_io_gitjournal_gitjournal_MainActivity_stringFromJNI( Java_io_gitjournal_gitjournal_Git_stringFromJNI(
JNIEnv *env, JNIEnv *env,
jobject /* this */) { jobject /* this */) {
@ -21,7 +21,7 @@ Java_io_gitjournal_gitjournal_MainActivity_stringFromJNI(
hello += " SSH Version: "; hello += " SSH Version: ";
hello += ssh2_version; hello += ssh2_version;
//git_libgit2_init(); git_libgit2_init();
int major; int major;
int minor; int minor;
int patch; int patch;

View File

@ -0,0 +1,13 @@
package io.gitjournal.gitjournal;
public class Git {
static {
System.loadLibrary("native-lib");
}
/**
* A native method that is implemented by the 'native-lib' native library,
* which is packaged with this application.
*/
public native String stringFromJNI();
}

View File

@ -21,23 +21,13 @@ import io.flutter.util.PathUtils;
// For MethodChannel // For MethodChannel
public class MainActivity extends FlutterActivity implements MethodCallHandler { public class MainActivity extends FlutterActivity implements MethodCallHandler {
static {
System.loadLibrary("native-lib");
}
/**
* A native method that is implemented by the 'native-lib' native library,
* which is packaged with this application.
*/
public native String stringFromJNI();
private static final String CHANNEL_NAME = "gitjournal.io/git"; private static final String CHANNEL_NAME = "gitjournal.io/git";
static MethodChannel channel; static MethodChannel channel;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
Log.d("VISH", stringFromJNI()); Git git = new Git();
Log.d("VISH", git.stringFromJNI());
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
GeneratedPluginRegistrant.registerWith(this); GeneratedPluginRegistrant.registerWith(this);