在编译so文件时,总会出现各类错误,上诉问题能够经过下面方法解决:html
The fastest way to get building is this:android
(1) Locate the Android.mk file that was used to build your native code before. This is usually somewhere under the project root. Make note of the path, you'll need it in a minute. Let's call it ~/projects/myproject/myapp/src/main/jni/Android.mk.app
(2) Find the build.gradle for that application. It should be in an ancestor folder of Android.mk. In our example, it would be located at ~/projects/myproject/myapp/build.gradle. If that file doesn't have "apply plugin: 'com.android.application'" near the top then it is probably the wrong one.gradle
(3) Edit that build.gradle to point to the Android.mk file. So, add a section like this:ui
android {
externalNativeBuild {
ndkBuild {
path "src/main/jni/Android.mk"
}
}
}
(4) Click "Sync Now" in Android Studio (or Build/Refresh Linked C++ Projects)this
At this point, there's a good chance the build will just work. If not, we have a new issue to deal with.code
FWIW, you can automate step 3 by following the steps here: https://developer.android.com/studio/projects/add-native-code.html#link-gradlehtm