标签:
今天看到一个有意思的项目--Termux,然后就把源码搞下来了。但是导入到Android Studio里编译运行的时候报错了!
java.lang.UnsatisfiedLinkError: com.android.tools.fd.runtime.IncrementalClassLoader$DelegateClassLoader[DexPathList[[dex file "/data/data/com.termux/files/instant-run/dex/slice-support-annotations-23.3.0_22f92d96560c582f4641cd755383bea196ee8431-classes.dex", dex file "/data/data/com.termux/files/instant-run/dex/slice-slice_9-classes.dex", dex file "/data/data/com.termux/files/instant-run/dex/slice-slice_8-classes.dex", dex file "/data/data/com.termux/files/instant-run/dex/slice-slice_7-classes.dex", dex file "/data/data/com.termux/files/instant-run/dex/slice-slice_6-classes.dex", dex file "/data/data/com.termux/files/instant-run/dex/slice-slice_5-classes.dex", dex file "/data/data/com.termux/files/instant-run/dex/slice-slice_4-classes.dex", dex file "/data/data/com.termux/files/instant-run/dex/slice-slice_3-classes.dex", dex file "/data/data/com.termux/files/instant-run/dex/slice-slice_2-classes.dex", dex file "/data/data/com.termux/files/instant-run/dex/slice-slice_1-classes.dex", dex file "/data/data/com.termux/files/instant-run/dex/slice-slice_0-classes.dex", dex file "/data/data/com.termux/files/instant-run/dex/slice-internal_impl-23.3.0_3144189e496bc31081b68ab24955a911f82ed66b-classes.dex", dex file "/data/data/com.termux/files/instant-run/dex/slice-com.android.support-support-vector-drawable-23.3.0_df3704b01aa38b8a7f534fb8d2a80f23e576bcf8-classes.dex", dex file "/data/data/com.termux/files/instant-run/dex/slice-com.android.support-support-v4-23.3.0_2a9351bfabee659f69965f79a9f0f22c2f914d2e-classes.dex", dex file "/data/data/com.termux/files/instant-run/dex/slice-com.android.support-appcompat-v7-23.3.0_8d8d2297d7a78b982c4922fea66c068a8e28fd02-classes.dex", dex file "/data/data/com.termux/files/instant-run/dex/slice-com.android.support-animated-vector-drawable-23.3.0_16904b6df415103ab22dadb9dcc59453ef887292-classes.dex"],nativeLibraryDirectories=[/data/app/com.termux-1/lib/x86, /vendor/lib, /system/lib]]] couldn‘t find "libtermux.so" at java.lang.Runtime.loadLibrary(Runtime.java:367) at java.lang.System.loadLibrary(System.java:1076) at com.termux.terminal.JNI.<clinit>(JNI.java:9) at com.termux.terminal.TerminalSession.initializeEmulator(TerminalSession.java:175) at com.termux.terminal.TerminalSession.updateSize(TerminalSession.java:151) at com.termux.view.TerminalView.updateSize(TerminalView.java:828) at com.termux.view.TerminalView.attachSession(TerminalView.java:227) at com.termux.app.TermuxActivity.switchToSession(TermuxActivity.java:584) at com.termux.app.TermuxActivity.addNewSession(TermuxActivity.java:577) at com.termux.app.TermuxActivity$11.run(TermuxActivity.java:479) at com.termux.app.TermuxInstaller.setupIfNeeded(TermuxInstaller.java:72) at com.termux.app.TermuxActivity.onServiceConnected(TermuxActivity.java:463) at android.app.LoadedApk$ServiceDispatcher.doConnected(LoadedApk.java:1223) at android.app.LoadedApk$ServiceDispatcher$RunConnection.run(LoadedApk.java:1240) at android.os.Handler.handleCallback(Handler.java:739) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:148) at android.app.ActivityThread.main(ActivityThread.java:5417) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
(其实现在我的内心是非常高兴的,原因你不懂。。)
然后我这个小白那是好一通查资料,终于明白了这个项目中人家在gradle文件中屏蔽掉了默认的jni编译生成过程
sourceSets { main { jni.srcDirs = [] } }
然后就需要手动使用ndk-build命令先编译好so文件然后才可以构建工程。我不想那么麻烦,依然想用gradle来完成,结果又是一通查。
解决方案如下:
首先把上面那段代码删掉,然后在defaultConfig中添加如下代码:
ndk{ moduleName "libtermux" cFlags "-std=c11 -Wall -Wextra -Os -fno-stack-protector" }
问题就愉快地解决啦。
注意!一定要有cFlags的配置,要不然会报这个错:
Error:(131, 9) error: ‘for‘ loop initial declarations are only allowed in C99 or C11 mode
标签:
原文地址:http://www.cnblogs.com/gufor/p/5460189.html