微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

android – 将项目迁移到新的实验gradle插件

我尝试将我的 Android项目迁移到新的实验性gradle插件.我按照 this页的说明进行操作.我对所需文件进行了更改,但是当我尝试使用gradle文件同步项目时出错.

Error:Unable to load class ‘com.android.build.gradle.managed.ProductFlavor_Impl’.
Possible causes for this unexpected error include:

  • Gradle’s dependency cache may be corrupt (this sometimes occurs after a network connection timeout.)
    Re-download dependencies and sync project (requires network)
  • The state of a Gradle build process (daemon) may be corrupt. Stopping all Gradle daemons may solve this problem.
    Stop Gradle build processes (requires restart)
  • Your project may be using a third-party plugin which is not compatible with the other plugins in the project or the version of Gradle requested by the project.

In the case of corrupt Gradle processes,you can also try closing the IDE and then killing all Java processes.

我的app文件夹中的build.gradle与此非常相似:

apply plugin: 'com.android.model.application'
apply plugin: 'maven'

repositories {
    maven {
        url = getBaseRepository()
        credentials {
            username = NEXUS_USERNAME
            password = NEXUS_PASSWORD
        }
    }
    mavenCentral()
}

def int CACHE_LIMIT = CACHE_CHANGING_MODULES_FOR_SECONDS.toInteger()

configurations.all {
    resolutionStrategy.cacheChangingModulesFor CACHE_LIMIT,'seconds'
}

model {
    android {
        compileSdkVersion = 23
        buildToolsversion = "23.0.0"

        defaultConfig.with {
            applicationId = "<myRealAppIdisHere>"
            minSdkVersion.apiLevel = 14
            targetSdkVersion.apiLevel = 18

            multiDexEnabled = true
        }
    }

    android.buildTypes {
        debug {
            /*buildConfigField.with {
                create() {
                    type = "boolean"
                    name = "DEBUG_BUILD"
                    value = rootProject.ext.debugBuild
                }
            }*/
        }
        release {
            minifyEnabled = false
            proguardFiles += 'proguard-rules.pro'
            /*buildConfigField.with {
                create() {
                    type = "boolean"
                    name = "DEBUG_BUILD"
                    value = rootProject.ext.releaseBuild
                }
            }*/
        }
    }
}


dependencies {
    // my dependencies are here...
}

有人知道问题出在哪里吗?我不知道为什么错误消息包含有关ProductFlavor的问题,因为我的项目没有味道……

UPDATE

我试图清理我的项目 – 清理不成功,但清理过程中的错误消息更具体:

Error:(10,1) A problem occurred configuring project ‘:app’.
Exception thrown while executing model rule: com.android.build.gradle.model.BaseComponentModelPlugin$Rules#createVariantData(org.gradle.model.ModelMap,org.gradle.model.ModelMap,com.android.build.gradle.internal.TaskManager) > afterEach()
Could not resolve all dependencies for configuration ‘:app:_debugCompile’.
Exception thrown while executing model rule: model.android
Cannot set readonly property: minSdkVersion for class: com.android.build.gradle.managed.ProductFlavor_Impl

但我仍然不知道如何解决它.

解决方法

如果这不是项目中的真实文件,请确保您具有:
minSdkVersion.apiLevel
targetSdkVersion.apiLevel

代替:

minSdkVersion
targetSdkVersion

我有同样的问题,这解决了它.

原文地址:https://www.jb51.cc/android/314468.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐