Android开发——增量更新实战中遇到的问题

0.   前言

之前一篇 Android开发——增量更新实战总结介绍了增量更新的具体实现步骤,但是其中有一些坑还是需要注意一下的,这里对遇到的一些坑做一个总结,希望以后遇到这些坑的同学少走弯路。

1.  Windows下的编译错误  

在上一篇的3.2我们导入源码的过程中,其中为了防止Windows下的编译错误放入了empty.c空文件,具体错误当时忘记截图了,反正如果你用的Windows平台做,直接加入就行了。说到这里还是觉得如果有钱就去入手MacBookPro,听同学说她实习所在的公司都是人手一台的,除了避免一些莫名其妙的BUG,还有就是下面的内存问题。

 

2.  内存问题  

我这实验室的4G内存的电脑有时候打开Studio就会报下面的错:

Gradle sync failed: Unable to start the daemonprocess.This problem might be caused by incorrect configuration of thedaemon.For example, an unrecognized jvm option is used.Please refer to the userguide chapter on the daemon at
https://docs.gradle.org/2.14.1/userguide/gradle_daemon.html
Please read the following process output tofind out more:
-----------------------
Error occurred during initialization of VM
Could not reserve enough space for 1572864KBobject heap
Consult IDE log for more details (Help | ShowLog)

每次遇到这种错误在gradle.properties文件中加入如下代码才可以正常使用,估计入手一台16G内存的Pro就不会这么麻烦了吧,反正我是打算要买了=。= 没有给苹果打广告,只是为了提高工作和学习效率而已。

org.gradle.jvmargs=-Xmx512m -XX:MaxPermSize=512m

 3.  cannot locate symbol "signal" referenced by "libbsdiff.so"问题  

我在Android4.2的手机上安装应用,点击按钮后应用崩溃,报错如下:

java.lang.UnsatisfiedLinkError: dlopen failed:cannot locate symbol "signal" referenced by"libbsdiff.so"...

这个错误几乎困扰了我整整两天,甚至卸载重装NDK都无济于事,后来Google解决方案。

3.1  minSdkVersion与platform不匹配

StackOverFlow上的这个帖子给出的答案是:

signal was an inline function until platformandroid-21, now it's not inline anymore.
When you use the ndk r10, android-21 is used bydefault but it's not fully retro-compatible with devices running former Androidversions. In your case, signal can't be found on your device (but it would runproperly on Lollipop).
When using the NDK, you should use the platform(APP_PLATFORM:=android-XX) that corresponds to your android:minSdkVersion.
So here you can set APP_PLATFORM:=android-15inside Application.mk Makefile, and your lib will use the inline version ofsignal, so it will not look for its symbol at runtime.

然而我在5.1的模拟器上尝试后依旧报错,并不是像上面所说的那样run properly on Lollipop。上面提到在Application.mk里加APP_PLATFORM:=android-XX看起来貌似就是解决方案,因为我在国内的一些博客里也看到有人这么做并且解决了这个错误,然而Android Studio的项目结构里并没有Application.mk这个文件,然后这就很尴尬了,自己在jni目录下手动添加Application.mk什么的也没效果。

然后看到上面帖子的答题人在评论区给出的在AndroidStudio里的修改方法:

You can modify the compileSdkVersion to changethe APP_PLATFORM version. 

我仿佛看到了新大陆,修改compileSdkVersion的版本,下载旧版本的开发工具,编译一下就报了一大堆错误,大多是资源错误,V7包依赖错误和其他的一些错误,尝试各种修改后心累到放弃了 ==

3.2  NDK位数和手机位数不匹配

继而在国外的另一个帖子里看到这句话:

If you get an error like CANNOT LINKEXECUTABLE: cannot locate symbol "signal" referenced by"gatord" on android, please ensure you are using the correct versionof the Android ndk: ndk32 for 32-bit targets and ndk64 for 64-bit targets.

于是我在确定手机是32位之后查看NDK是不是32位的,发现一样是32位的,问题依然没有得到解决。

3.3  NDK版本问题

最后在StackOverFlow这个帖子里关注到有人通过修改NDK版本解决了cannot locate symbol "signal"的错误

Had this problem and solved reverting to ndk r9.

于是我便去找到了r9b的资源包,替换掉新版本后出现了一堆新的错误,这时我几乎都要放弃了== ,几番波折下载到了r10的旧版本并尝试编译运行后,错误奇迹般地解决了。我TM还能说什么呢,真的是坑死了。

  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,关于您的问题,我会尽力回答。在Android,JNI可以用来与C/C++代码进行交互,我们可以利用JNI来读写SD卡。下面是一个简单的例子: 1. 首先,在您的Java代码定义native方法: ``` public class MainActivity extends Activity { static { System.loadLibrary("native-lib"); } public native String readFromSDCard(String filePath); public native boolean writeToSDCard(String filePath, String content); } ``` 2. 然后,在您的C/C++代码实现这些方法: ``` #include <jni.h> #include <string.h> #include <stdio.h> #include <android/log.h> JNIEXPORT jstring JNICALL Java_com_example_myapplication_MainActivity_readFromSDCard(JNIEnv *env, jobject instance, jstring filePath) { const char *path = env->GetStringUTFChars(filePath, 0); FILE *file = fopen(path, "r"); if (file == NULL) { __android_log_print(ANDROID_LOG_ERROR, "JNI", "readFromSDCard: fopen failed"); return NULL; } fseek(file, 0, SEEK_END); long size = ftell(file); fseek(file, 0, SEEK_SET); char *buffer = new char[size + 1]; fread(buffer, 1, size, file); buffer[size] = '\0'; fclose(file); env->ReleaseStringUTFChars(filePath, path); return env->NewStringUTF(buffer); } JNIEXPORT jboolean JNICALL Java_com_example_myapplication_MainActivity_writeToSDCard(JNIEnv *env, jobject instance, jstring filePath, jstring content) { const char *path = env->GetStringUTFChars(filePath, 0); const char *str = env->GetStringUTFChars(content, 0); FILE *file = fopen(path, "w"); if (file == NULL) { __android_log_print(ANDROID_LOG_ERROR, "JNI", "writeToSDCard: fopen failed"); return false; } fwrite(str, 1, strlen(str), file); fclose(file); env->ReleaseStringUTFChars(filePath, path); env->ReleaseStringUTFChars(content, str); return true; } ``` 3. 最后,在您的AndroidManifest.xml文件添加以下权限: ``` <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> ``` 这样,您就可以在Java代码调用这些native方法来读写SD卡了。 至于Android NDK的使用实例——增量更新实战,这是一个比较复杂的话题,如果您有相关的需求,可以提出具体的问题,我会尽力为您解答。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值