方法:把Top-level build file修改為這個樣子
build.gradle:
<span style="color:#009900;"></span><pre style="background-color:#2b2b2b;color:#a9b7c6;font-family:'宋體';font-size:13.5pt;"><span style="color:#808080;">// Top-level build file where you can add configuration options common to all sub-projects/modules.
</span>buildscript {
repositories {
jcenter()
}
dependencies {
classpath <span style="color:#6a8759;">'com.android.tools.build:gradle:1.5.0'
</span><span style="color:#6a8759;">
</span><span style="color:#6a8759;"> </span><span style="color:#808080;">// NOTE: Do not place your application dependencies here; they belong
</span><span style="color:#808080;"> // in the individual module build.gradle files
</span><span style="color:#808080;"> </span>}
}
allprojects {
repositories {
jcenter()
}
}
task clean(<span style="color:#d0d0ff;">type</span>: <span style="color:#769aa5;">Delete</span>) {
delete <span style="color:#9876aa;">rootProject</span>.<span style="color:#9876aa;">buildDir
</span>}
當然build tools plugin版本還是寫AndroidStudio中的版本(我的是1.5.0),主要是把dependencies{...} ?android{...}刪掉,我是這樣做的。然後去sync project with gradle,發現問題解決了。
當使用到DNK出現的問題
1) Error:(199) *** Android NDK: Aborting... .? Stop.
2)Error:Execution failed for task ':app:compileDebugNdk'.
解決方法:進入到app/build.gradle,進行如下修改。
sourceSets.main {
jniLibs.srcDir 'libs'
jni.srcDirs = []
}
然後去sync project with gradle,發現問題解決了。
也可以去查看stackoverflow中的解答:
/questions/27735646/android-studio-gradle-dsl-method-not-found-android-error17-0
/questions/28759505/execution-failed-for-task-appcompiledebugndk