Android Studio 3.0 - Gradle externalNativeBuild 同步失败

Android Studio 3.0 - Gradle Sync failed for externalNativeBuild

我在迁移到 Android studio 3.0

时收到以下回溯
* What went wrong:
Could not determine the dependencies of task ':celltower:compileExternalNativeBuildJavaWithJavac'.
> Could not resolve all task dependencies for configuration ':celltower:externalNativeBuildCompileClasspath'.
   > Could not resolve project :commonandroidutils.
     Required by:
         project :celltower
      > Unable to find a matching configuration of project :commonandroidutils:
          - Configuration 'debugApiElements':
              - Required com.android.build.api.attributes.BuildTypeAttr 'externalNativeBuild' and found incompatible value 'debug'.
              - Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and found compatible value 'Aar'.
              - Found com.android.build.gradle.internal.dependency.VariantAttr 'debug' but wasn't required.
              - Required org.gradle.api.attributes.Usage 'java-api' and found compatible value 'java-api'.
          - Configuration 'debugRuntimeElements':
              - Required com.android.build.api.attributes.BuildTypeAttr 'externalNativeBuild' and found incompatible value 'debug'.
              - Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and found compatible value 'Aar'.
              - Found com.android.build.gradle.internal.dependency.VariantAttr 'debug' but wasn't required.
              - Required org.gradle.api.attributes.Usage 'java-api' and found incompatible value 'java-runtime'.
          - Configuration 'releaseApiElements':
              - Required com.android.build.api.attributes.BuildTypeAttr 'externalNativeBuild' and found incompatible value 'release'.
              - Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and found compatible value 'Aar'.
              - Found com.android.build.gradle.internal.dependency.VariantAttr 'release' but wasn't required.
              - Required org.gradle.api.attributes.Usage 'java-api' and found compatible value 'java-api'.
          - Configuration 'releaseRuntimeElements':
              - Required com.android.build.api.attributes.BuildTypeAttr 'externalNativeBuild' and found incompatible value 'release'.
              - Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and found compatible value 'Aar'.
              - Found com.android.build.gradle.internal.dependency.VariantAttr 'release' but wasn't required.
              - Required org.gradle.api.attributes.Usage 'java-api' and found incompatible value 'java-runtime'.
   > Could not resolve project :wimtutils.
     Required by:
         project :celltower
      > Unable to find a matching configuration of project :wimtutils:
          - Configuration 'debugApiElements':
              - Required com.android.build.api.attributes.BuildTypeAttr 'externalNativeBuild' and found incompatible value 'debug'.
              - Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and found compatible value 'Aar'.
              - Found com.android.build.gradle.internal.dependency.VariantAttr 'debug' but wasn't required.
              - Required org.gradle.api.attributes.Usage 'java-api' and found compatible value 'java-api'.
          - Configuration 'debugRuntimeElements':
              - Required com.android.build.api.attributes.BuildTypeAttr 'externalNativeBuild' and found incompatible value 'debug'.
              - Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and found compatible value 'Aar'.
              - Found com.android.build.gradle.internal.dependency.VariantAttr 'debug' but wasn't required.
              - Required org.gradle.api.attributes.Usage 'java-api' and found incompatible value 'java-runtime'.
          - Configuration 'releaseApiElements':
              - Required com.android.build.api.attributes.BuildTypeAttr 'externalNativeBuild' and found incompatible value 'release'.
              - Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and found compatible value 'Aar'.
              - Found com.android.build.gradle.internal.dependency.VariantAttr 'release' but wasn't required.
              - Required org.gradle.api.attributes.Usage 'java-api' and found compatible value 'java-api'.
          - Configuration 'releaseRuntimeElements':
              - Required com.android.build.api.attributes.BuildTypeAttr 'externalNativeBuild' and found incompatible value 'release'.
              - Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and found compatible value 'Aar'.
              - Found com.android.build.gradle.internal.dependency.VariantAttr 'release' but wasn't required.
              - Required org.gradle.api.attributes.Usage 'java-api' and found incompatible value 'java-runtime'.

我的 build.gradle 到了。

apply plugin: 'com.android.library'

android {
    compileSdkVersion 26
    buildToolsVersion "26.0.1"

    defaultConfig {
        minSdkVersion 15
        targetSdkVersion 22
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        externalNativeBuild {
            ndkBuild {
            }
        }

        ndk {
//            abiFilters   "armeabi-v7a", "x86"
            abiFilters "armeabi-v7a"
            moduleName "HelloJNI"
            //ldLibs.addAll(["android", "log"])
        }
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
        debug {
            debuggable true
            minifyEnabled false

            ndk {
                abiFilters   "armeabi-v7a", "x86"
                moduleName "HelloJNI"
            }
        }
        externalNativeBuild {
            ndkBuild {
                path "src/main/jni/Android.mk"
            }
        }
    }

    buildTypeMatching 'debug', 'release'

    compileOptions {
        targetCompatibility 1.8
        sourceCompatibility 1.8
    }
}

ext {
    retrofitVersion = '2.1.0'
    rxJavaVersion = '1.2.1'
    rxAndroidVersion = '1.2.1'
    okHttpVersion = '3.4.1'
    playServicesVersion = '9.8.0'
    fireBaseVersion = '9.8.0'
    daggerVersion = '2.7'
    appCompatV7Version = '26.0.1'
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    implementation "com.android.support:support-annotations:$appCompatV7Version"
    implementation 'com.google.code.gson:gson:2.7'
    testImplementation 'junit:junit:4.12'
    implementation 'com.squareup.retrofit:retrofit:1.9.0'
    implementation 'com.jakewharton.retrofit:retrofit1-okhttp3-client:1.0.2'
    implementation "com.squareup.retrofit2:retrofit:$retrofitVersion"
    implementation "com.squareup.retrofit2:adapter-rxjava:$retrofitVersion"
    implementation "com.squareup.retrofit2:converter-gson:$retrofitVersion"
    implementation 'com.readystatesoftware.sqliteasset:sqliteassethelper:+'
    implementation project(':commonandroidutils')
    implementation project(':wimtutils')
}

非常感谢任何帮助!

仅针对最后两个项目依赖项尝试将 implementation 替换为 api

  1. commonandroidutils
  2. wimutils

文档指出:

依赖项在编译时可供模块使用,在编译时和运行时也可供模块的使用者使用。此配置的行为就像 compile(现已弃用),您通常应该只在 库模块 中使用它。应用程序模块应使用 implementation,除非您想 将其 API 公开给单独的 测试模块。

参考:Migrate to Android Plugin for Gradle 3.0.0

不确定,但请尝试一下。希望对你有帮助。

我不确定这怎么可能。 Gradle 插件本身与其提供 WaitableExecutor class.

的依赖项之间似乎不匹配

但是你提到 Gradle 1.5,这是个问题。

插件版本0.3兼容Gradle1.3-1.4 上周新版本发布,0.4兼容Gradle1.6+

确保使用 0.4 和新的 Gradle 版本。

我将 externalNativeBuild 移到了 buildTypes 之外,并将其放在 android 下。它开始工作了。

android {
....
...
   buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
        debug {
            debuggable true
            minifyEnabled false

            ndk {
                abiFilters   "armeabi-v7a", "x86"
                moduleName "HelloJNI"
            }
        }
    }

    externalNativeBuild {
        ndkBuild {
            path "src/main/jni/Android.mk"
        }
    }

    buildTypeMatching 'debug', 'release'
...
....
} // end of android