首先在src同级目录下创建libs目录讲需要的.so复制到这里效果如图
然后在app级别的build.gradle配置lib路径,效果如果 完整代码如下:
apply plugin: 'com.android.application'android { compileSdkVersion 24 buildToolsVersion "25.0.1" defaultConfig { applicationId "com.liberation.idcarread" minSdkVersion 15 targetSdkVersion 24 versionCode 1 versionName "1.0" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" } buildTypes { release { minifyEnabled false PRoguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } task nativeLibsToJar(type: Zip, description: "create a jar archive of the native libs") { destinationDir file("$projectDir/libs") baseName "Native_Libs2" extension "jar" from fileTree(dir: "libs", include: "**/*.so") into "lib" } tasks.withType(javaCompile) { compileTask -> compileTask.dependsOn(nativeLibsToJar) } sourceSets { main { jniLibs.srcDirs = ['libs'] } }}dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { exclude group: 'com.android.support', module: 'support-annotations' }) compile 'com.android.support:appcompat-v7:24.2.1' testCompile 'junit:junit:4.12'}至此配置完成点击sync即可正常使用。编译运行过程遇到*.so: has text relocations 说明编译.so文件时使用了较低版本sdk 版本 此时降低build.gradle的targetSdkVersion 版本为22以及以下即可 我们这里改为22 最终效果如下
运行时又出现一个异常
**java.lang.UnsatisfiedLinkError: No implementation found for int com.liberation.idcarread.ivsign.IDCReaderSDK.wltInit(java.lang.String) (tried Java_com_liberation_idcarread_ivsign_IDCReaderSDK_wltInit and Java_com_liberation_idcarread_ivsign_IDCReaderSDK_wltInit__Ljava_lang_String_2)**解决方法:按照官方Demo放好包名路径。包名一定要跟原来的一模一样负责无法调用!
新闻热点
疑难解答