我从here使用bsdiff.so文件作为我的项目。
这是我的项目结构。
我将<div class="container">
<article>
<p> @Model.EventName </p>
<img src="@Url.Action("DisplayImg", "Event" )" />
</article>
添加到我的build.gradle文件中。
jniLibs.srcDirs
我有两个来自该库的类使用此c文件。
BsPatch:
apply plugin: 'com.android.application'
android {
compileSdkVersion 24
buildToolsVersion "25.0.0"
defaultConfig {
applicationId "com.test.testbsdiff"
minSdkVersion 16
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'
}
}
sourceSets {
main {
jniLibs.srcDirs = ['libs']
//jni.srcDirs = [] //disable automatic ndk-build call
}
}
}
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'
}
BsPatchAsyncTask:
import java.io.File;
/**
* patch入口
* Created by shoyu666 on 16/7/12.
*/
public class BsPatch {
public static final String TAG = "BsPatch";
static {
System.loadLibrary("bsdiff");
}
/**
* patch操作
*
* @param old 老的apk路径
* @param patch 补丁路径
* @param newapk 新的apk路径
*/
public static native void bspatch(String old, String patch, String newapk);
/**
* 测试下库是否正常
*
* @return
*/
public static native String test();
/**
* 启动一部patch
*
* @param files
*/
public static void patchSync(File... files) {
BsPatchAsyncTask task = new BsPatchAsyncTask();
task.execute(files);
}
}
当在mainactivity中使用此类和库时,我收到此错误:
import android.os.AsyncTask;
import java.io.File;
/**
* 异步patch
* Created by shoyu666 on 16/7/11.
*/
public class BsPatchAsyncTask extends AsyncTask<File, Integer, File> {
@Override
protected File doInBackground(File... files) {
if (checkParams(files)) {
File old = files[0];
File patcher = files[1];
File newFile = files[2];
try {
BsPatch.bspatch(old.getAbsolutePath(), patcher.getAbsolutePath(), newFile.getAbsolutePath());
} catch (Exception e) {
e.printStackTrace();
}
if (newFile.exists()) {
return newFile;
}
}
return null;
}
private boolean checkParams(File... files) {
boolean result = false;
if (files != null && files.length == 3) {
File old = files[0];
File patcher = files[1];
File newFile = files[2];
if (old != null && patcher != null && old.canRead() && patcher.canRead()) {
if (newFile.exists()) {
newFile.delete();
}
result = true;
}
}
return result;
}
}
主要活动:
java.lang.UnsatisfiedLinkError: Native method not found: ir.javadroid.testbsdiff.BsPatch.test:()Ljava/lang/String;
at ir.javadroid.testbsdiff.BsPatch.test(Native Method)
at ir.javadroid.testbsdiff.MainActivity.onCreate(MainActivity.java:15)
at android.app.Activity.performCreate(Activity.java:5264)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1088)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2302)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2390)
at android.app.ActivityThread.access$800(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1321)
at android.os.Handler.dispatchMessage(Handler.java:110)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:5292)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:824)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:640)
at dalvik.system.NativeStart.main(Native Method)