mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-06-29 10:17:16 +08:00
First integration of libgit2 in the Android App
This will allow us to remove the jgit dependency. JGit is annoying because we have to use an old version in order to support older API versions. Additionally, there are some subtle differences in their implementation. Finally, for iOS and desktop we will be using libgit2, so we may as well use the same stack on Android.
This commit is contained in:
@ -44,13 +44,21 @@ android {
|
|||||||
versionCode flutterVersionCode.toInteger()
|
versionCode flutterVersionCode.toInteger()
|
||||||
versionName flutterVersionName
|
versionName flutterVersionName
|
||||||
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
|
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
|
||||||
/*
|
|
||||||
externalNativeBuild {
|
externalNativeBuild {
|
||||||
cmake {
|
cmake {
|
||||||
cppFlags ""
|
cppFlags ""
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*/
|
ndk {
|
||||||
|
abiFilters 'x86', 'x86_64', 'armeabi-v7a', 'arm64-v8a'
|
||||||
|
}
|
||||||
|
sourceSets {
|
||||||
|
main {
|
||||||
|
jniLibs.srcDirs = ['libs']
|
||||||
|
java.srcDirs = ['src']
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
signingConfigs {
|
signingConfigs {
|
||||||
@ -66,13 +74,19 @@ android {
|
|||||||
signingConfig signingConfigs.release
|
signingConfig signingConfigs.release
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
externalNativeBuild {
|
externalNativeBuild {
|
||||||
cmake {
|
cmake {
|
||||||
path "src/main/cpp/CMakeLists.txt"
|
path "src/main/cpp/CMakeLists.txt"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
dexOptions {
|
||||||
|
incremental true
|
||||||
|
preDexLibraries true
|
||||||
|
jumboMode true
|
||||||
|
javaMaxHeapSize "12g"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
flutter {
|
flutter {
|
||||||
|
@ -1,6 +1,57 @@
|
|||||||
cmake_minimum_required(VERSION 3.4.1)
|
cmake_minimum_required(VERSION 3.4.1)
|
||||||
|
|
||||||
|
macro(print_all_variables)
|
||||||
|
message(STATUS "print_all_variables------------------------------------------{")
|
||||||
|
get_cmake_property(_variableNames VARIABLES)
|
||||||
|
foreach (_variableName ${_variableNames})
|
||||||
|
message(STATUS "${_variableName}=${${_variableName}}")
|
||||||
|
endforeach ()
|
||||||
|
message(STATUS "print_all_variables------------------------------------------}")
|
||||||
|
endmacro()
|
||||||
|
|
||||||
add_library( native-lib
|
|
||||||
SHARED
|
set(lib_src_DIR ${CMAKE_SOURCE_DIR}/../../../libs/${ANDROID_ABI})
|
||||||
native-lib.cpp )
|
include_directories(${lib_src_DIR}/include)
|
||||||
|
|
||||||
|
add_library(openssl-lib
|
||||||
|
STATIC
|
||||||
|
IMPORTED)
|
||||||
|
|
||||||
|
set_target_properties(openssl-lib
|
||||||
|
PROPERTIES IMPORTED_LOCATION
|
||||||
|
${lib_src_DIR}/lib/libssl.a)
|
||||||
|
|
||||||
|
|
||||||
|
add_library(crypto-lib
|
||||||
|
STATIC
|
||||||
|
IMPORTED)
|
||||||
|
|
||||||
|
set_target_properties(crypto-lib
|
||||||
|
PROPERTIES IMPORTED_LOCATION
|
||||||
|
${lib_src_DIR}/lib/libcrypto.a)
|
||||||
|
|
||||||
|
|
||||||
|
add_library(ssh2-lib
|
||||||
|
STATIC
|
||||||
|
IMPORTED)
|
||||||
|
|
||||||
|
set_target_properties(ssh2-lib
|
||||||
|
PROPERTIES IMPORTED_LOCATION
|
||||||
|
${lib_src_DIR}/lib/libssh2.a)
|
||||||
|
|
||||||
|
|
||||||
|
add_library(git2-lib
|
||||||
|
STATIC
|
||||||
|
IMPORTED)
|
||||||
|
|
||||||
|
set_target_properties(git2-lib
|
||||||
|
PROPERTIES IMPORTED_LOCATION
|
||||||
|
${lib_src_DIR}/lib/libgit2.a)
|
||||||
|
|
||||||
|
add_library(native-lib
|
||||||
|
SHARED
|
||||||
|
native-lib.cpp)
|
||||||
|
|
||||||
|
# The order of these libraries is super dooper important
|
||||||
|
# Otherwise you'll get linker errors
|
||||||
|
target_link_libraries(native-lib git2-lib ssh2-lib openssl-lib crypto-lib)
|
||||||
|
@ -1,10 +1,36 @@
|
|||||||
#include <jni.h>
|
#include <jni.h>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#include <openssl/err.h>
|
||||||
|
#include <openssl/crypto.h>
|
||||||
|
#include <libssh2.h>
|
||||||
|
#include <git2.h>
|
||||||
|
|
||||||
extern "C" JNIEXPORT jstring JNICALL
|
extern "C" JNIEXPORT jstring JNICALL
|
||||||
Java_io_gitjournal_gitjournal_MainActivity_stringFromJNI(
|
Java_io_gitjournal_gitjournal_MainActivity_stringFromJNI(
|
||||||
JNIEnv* env,
|
JNIEnv *env,
|
||||||
jobject /* this */) {
|
jobject /* this */) {
|
||||||
std::string hello = "Hello from C++";
|
|
||||||
|
ERR_load_crypto_strings();
|
||||||
|
const char *openssl_version = OpenSSL_version(0);
|
||||||
|
const char *ssh2_version = libssh2_version(0);
|
||||||
|
|
||||||
|
std::string hello = "Hello from C++: ";
|
||||||
|
hello += openssl_version;
|
||||||
|
hello += " SSH Version: ";
|
||||||
|
hello += ssh2_version;
|
||||||
|
|
||||||
|
//git_libgit2_init();
|
||||||
|
int major;
|
||||||
|
int minor;
|
||||||
|
int patch;
|
||||||
|
git_libgit2_version(&major, &minor, &patch);
|
||||||
|
|
||||||
|
hello += " Git version: ";
|
||||||
|
char n_str[20];
|
||||||
|
sprintf(n_str, "%d.%d.%d", major, minor, patch);
|
||||||
|
hello += n_str;
|
||||||
|
|
||||||
return env->NewStringUTF(hello.c_str());
|
return env->NewStringUTF(hello.c_str());
|
||||||
}
|
}
|
||||||
|
@ -21,15 +21,15 @@ import io.flutter.util.PathUtils;
|
|||||||
// For MethodChannel
|
// For MethodChannel
|
||||||
|
|
||||||
public class MainActivity extends FlutterActivity implements MethodCallHandler {
|
public class MainActivity extends FlutterActivity implements MethodCallHandler {
|
||||||
//static {
|
static {
|
||||||
// System.loadLibrary("native-lib");
|
System.loadLibrary("native-lib");
|
||||||
//}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A native method that is implemented by the 'native-lib' native library,
|
* A native method that is implemented by the 'native-lib' native library,
|
||||||
* which is packaged with this application.
|
* which is packaged with this application.
|
||||||
*/
|
*/
|
||||||
//public native String stringFromJNI();
|
public native String stringFromJNI();
|
||||||
|
|
||||||
|
|
||||||
private static final String CHANNEL_NAME = "gitjournal.io/git";
|
private static final String CHANNEL_NAME = "gitjournal.io/git";
|
||||||
@ -37,7 +37,7 @@ public class MainActivity extends FlutterActivity implements MethodCallHandler {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
//Log.d("VISH", stringFromJNI());
|
Log.d("VISH", stringFromJNI());
|
||||||
|
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
GeneratedPluginRegistrant.registerWith(this);
|
GeneratedPluginRegistrant.registerWith(this);
|
||||||
|
Reference in New Issue
Block a user