将带有jni的Eclipse项目导入AndroidStudio遇到的问题

当然前提是本地已经配置好了ndk的环境

1. NDK integration is deprecated in the current plugin

首次编译遇到一个错误:

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:compileDebugNdk'.
> Error: NDK integration is deprecated in the current plugin.  Consider trying the new experimental plugin.  For details, see http://tools.android.com/tech-docs/new-build-system/gradle-experimental.  Set "$USE_DEPRECATED_NDK=true" in gradle.properties to continue using the current NDK integration.

解决

先在module下新建文件,gradle.properties

文件中写上一句 android.useDeprecatedNdk=true

然后重新build就没这个问题了

2. Native C/C++ source code is found, but it seems that NDK option is not configured

Warning: Native C/C++ source code is found, but it seems that NDK option is not configured.  Note that if you have an Android.mk, it is not used for compilation.  The recommended workaround is to remove the default jni source code directory by adding: 
 android {
    sourceSets {
        main {
            jni.srcDirs = []
        }
    }
}
to build.gradle, manually compile the code with ndk-build, and then place the resulting shared object in src/main/jniLibs.

build失败在Gradle Console中会打印这个信息

解决

其中一种方法就是,就按他提示的吧,加上

sourceSets {
        main {
            jni.srcDirs = []
        }
    }

再次build ,:

BUILD SUCCESSFUL

猜你喜欢

转载自blog.csdn.net/qq_25806863/article/details/74940903