1. 程式人生 > >將帶有jni的Eclipse專案匯入AndroidStudio遇到的問題

將帶有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