Add POC Android JNI integration

I want to stop using jgit and instead of libgit2 instead. I feel far
more confident with the latter, and I need to use it for ios anyway.

Currently I cannot use the latest version of jgit as that requires a
higher minSDKVersion, and I want to target older android devices as
well.
This commit is contained in:
Vishesh Handa
2019-02-09 01:36:42 +01:00
parent bd9ca896bf
commit 1845faded9
4 changed files with 39 additions and 0 deletions

View File

@ -44,6 +44,11 @@ android {
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
externalNativeBuild {
cmake {
cppFlags ""
}
}
}
signingConfigs {
@ -59,6 +64,11 @@ android {
signingConfig signingConfigs.release
}
}
externalNativeBuild {
cmake {
path "src/main/cpp/CMakeLists.txt"
}
}
}
flutter {

View File

@ -0,0 +1,6 @@
cmake_minimum_required(VERSION 3.4.1)
add_library( native-lib
SHARED
native-lib.cpp )

View File

@ -0,0 +1,10 @@
#include <jni.h>
#include <string>
extern "C" JNIEXPORT jstring JNICALL
Java_io_gitjournal_gitjournal_MainActivity_stringFromJNI(
JNIEnv* env,
jobject /* this */) {
std::string hello = "Hello from C++";
return env->NewStringUTF(hello.c_str());
}

View File

@ -21,11 +21,24 @@ import io.flutter.util.PathUtils;
// For MethodChannel
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";
static MethodChannel channel;
@Override
protected void onCreate(Bundle savedInstanceState) {
Log.d("VISH", stringFromJNI());
super.onCreate(savedInstanceState);
GeneratedPluginRegistrant.registerWith(this);