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

带有 Gradle 7.1.0-alpha03 和 Composer 的新 Android 项目无法构建

如何解决带有 Gradle 7.1.0-alpha03 和 Composer 的新 Android 项目无法构建

所以我今天在 Android Studio 中创建了一个新项目“2021.1.1 Canary 3”版本,但它无法正确构建我的项目。

> Build file 'C:\Users\arash\Desktop\JPCompose\app\build.gradle' line: 2
> 
> Plugin [id: 'com.android.application',version: '7.1.0-alpha03'] was
> not found in any of the following sources:
> 
> * Try: Run with --info or --debug option to get more log output. Run with --scan to get full insights.
> 
> * Exception is: org.gradle.api.plugins.UnkNownPluginException: Plugin [id: 'com.android.application',version: '7.1.0-alpha03'] was not
> found in any of the following sources:
> 
> - Gradle Core Plugins (plugin is not in 'org.gradle' namespace)
> - Plugin Repositories (Could not resolve plugin artifact 'com.android.application:com.android.application.gradle.plugin:7.1.0-alpha03')
> Searched in the following repositories:
>     Gradle Central Plugin Repository
>     Google
>     MavenRepo

这是 Gradle 的应用程序版本:

plugins {
    id 'com.android.application'
    id 'org.jetbrains.kotlin.android'
}

android {
    compileSdk 30
    buildToolsversion "30.0.3"

    defaultConfig {
        applicationId "com.arash.afsharpour.jpcompose"
        minSdk 21
        targetSdk 30
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        vectorDrawables {
            useSupportLibrary true
        }
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'),'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    kotlinoptions {
        jvmTarget = '1.8'
    }
    buildFeatures {
        compose true
    }
    compoSEOptions {
        kotlinCompilerExtensionVersion compose_version
    }
}

dependencies {

    implementation 'androidx.core:core-ktx:1.3.2'
    implementation 'androidx.appcompat:appcompat:1.2.0'
    implementation 'com.google.android.material:material:1.3.0'
    implementation "androidx.compose.ui:ui:$compose_version"
    implementation "androidx.compose.material:material:$compose_version"
    implementation "androidx.compose.ui:ui-tooling:$compose_version"
    implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.3.1'
    implementation 'androidx.activity:activity-compose:1.3.0-alpha06'
    testImplementation 'junit:junit:4.+'
    androidTestImplementation 'androidx.test.ext:junit:1.1.2'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
    androidTestImplementation "androidx.compose.ui:ui-test-junit4:$compose_version"
}

下面是我的 Gradle 的项目版本:

task clean(type: Delete) {
    delete rootProject.buildDir
}

buildscript {
    ext {
        compose_version = '1.0.0-beta09'
    }
}

下面是settings.gradle:

pluginManagement {
    repositories {
        gradlePluginPortal()
        google()
        mavenCentral()
    }
    plugins {
        id 'com.android.application' version '7.1.0-alpha03'
        id 'com.android.library' version '7.1.0-alpha03'
        id 'org.jetbrains.kotlin.android' version '1.5.10'
    }
}
dependencyResolutionManagement {
    repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
    repositories {
        google()
        mavenCentral()
    }
}
rootProject.name = "JPCompose"
include ':app'

我也试过将 Kotlin 的版本降低到 1.5.0 也没有用,因为我已经搜索了很长时间并且没有找到任何像我所拥有的那样远程的东西,希望这个版本可以向谷歌报告这个严重的问题。

解决方法

好的,截至目前 2021 年 7 月 23 日,没有其他修复程序,您需要做的就是将 Gradle 版本降级到 6.7。 1gradle-wrapper.properties 中并将插件降级到 4.2.2。另外,你必须清空你的 gradle.setting 并像过去一样使用 Gradle,我在下面添加了我的,所以你可以这样做:

gradle-wrapper.properties:

distributionBase=GRADLE_USER_HOME
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-bin.zip
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME

Setting.Gradle:

include ':app'
rootProject.name = "YourProjectName"

并删除所有其他内容。

build.gradle(项目):

buildscript {
    ext.compose_version = "1.0.0-rc02"
    ext.kotlin_version = "1.5.10"
    ext.room_version = "2.3.0"
    ext.dagger_hilt_version = "2.37"
    ext.coroutines_version = "1.5.0"
    ext.navigation_components_version = "2.3.5"
    ext.glide_version = "4.11.0"
    ext.java_version = JavaVersion.VERSION_1_8

    repositories {
        google()
        mavenCentral()
    }
    dependencies {
        classpath "com.android.tools.build:gradle:4.2.2"
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath "androidx.navigation:navigation-safe-args-gradle-plugin:$navigation_components_version"
        classpath "com.google.dagger:hilt-android-gradle-plugin:$dagger_hilt_version"
    }

}

allprojects {
    repositories {
        google()
        mavenCentral()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

希望它能帮助你继续。快乐编码

,

我没有这些版本,它运行良好。喜欢:

    plugins {
    id 'com.android.application'
    id 'kotlin-android'
}

也许试试看?

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

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?