无法解决依赖项':app@debug/compileClasspath'的问题:无法解决androidx

3

我正在开发一个 Android 应用,这是一个非常庞大的项目,包含了许多类。今天我想要创建一个新的类,然后我遇到了以下代码:

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;

    public class Main2Activity extends AppCompatActivity {

        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main2);
        }
    }

你可以看到这行:

import androidx.appcompat.app.AppCompatActivity;

这里的appcompat是红色的。

而旧的类都有下面这行代码:

import android.support.v7.app.AppCompatActivity;

XML 代码如下:

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".Main2Activity">

</androidx.constraintlayout.widget.ConstraintLayout>

您可以看到androidx。我尝试删除类并重新创建,还尝试创建新的片段而不是类,但所有内容都与x一起创建。
几天前,我将库从27更新到28,我不知道是否会导致这个问题。现在我无法同步项目,我只得到了这些错误:
无法解决“:app@debug / compileClasspath”的依赖关系:无法解析androidx.constraintlayout:constraintlayout:1.1.2。打开文件显示详细信息
无法解决“:app@debugAndroidTest / compileClasspath”的依赖关系:无法解析androidx.constraintlayout:constraintlayout:1.1.2。打开-文件显示详细信息
这是应用gradle:
apply plugin: 'com.android.application'

android {
    compileSdkVersion 28
    buildToolsVersion "27.0.3"
    defaultConfig {
        applicationId "giga.net.world.GN"
        minSdkVersion 16
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        aaptOptions {
            cruncherEnabled = false
        }
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'androidx.constraintlayout:constraintlayout:1.1.2'
    androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })

    implementation 'com.android.support:appcompat-v7:28.0.0-alpha1'
    implementation 'com.android.support:design:28.0.0-alpha1'
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    implementation 'com.android.support:cardview-v7:28.0.0-alpha1'
    implementation 'com.android.support:recyclerview-v7:28.0.0-alpha1'
    implementation 'com.squareup.picasso:picasso:2.71828'
    implementation 'com.jakewharton:butterknife:8.8.1'
    implementation 'com.roughike:bottom-bar:2.0.2'
    implementation 'com.android.support:palette-v7:28.0.0-alpha1'
    implementation 'com.android.support:support-v4:28.0.0-alpha1'
    testImplementation 'junit:junit:4.12'
    annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'
    implementation 'com.android.support:support-core-utils:28.0.0-alpha1'
    implementation 'net.alexandroid.utils:mylog:1.1'
    implementation 'com.google.android.exoplayer:exoplayer:r1.5.16'
    implementation project(':playercontrolview')
}

以及项目Gradle:

buildscript {
    repositories {
        jcenter()
        mavenCentral()
        google()
        maven {
            url "https://maven.google.com"
        }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.3.0-alpha02'
        classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.0'
        classpath 'com.github.dcendents:android-maven-gradle-plugin:1.4.1'
        classpath 'com.novoda:bintray-release:0.5.0'
//        classpath 'com.google.gms:google-services:3.0.0'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
        mavenCentral()
        google()
        maven {
            url "https://maven.google.com"
        }
    }
}

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

还有一个包含主要项目的库项目,它的Gradle是:

apply plugin: 'com.android.library'
apply plugin: 'com.novoda.bintray-release'

android {
    compileSdkVersion 27
    buildToolsVersion "27.0.3"

    defaultConfig {
        minSdkVersion 16
        targetSdkVersion 27
        versionCode 1
        versionName "1.0.1"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    lintOptions {
        abortOnError false
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    testImplementation 'junit:junit:4.12'
    implementation 'com.android.support:appcompat-v7:27.1.1'
}

publish {
    userOrg = 'ogapants'
    groupId = 'com.github.ogapants.playercontrolview'
    artifactId = 'playercontrolview'
    publishVersion = '1.0.1'
    desc = 'This library provides easily customizable MediaController for Android'
    website = 'https://github.com/ogapants/PlayerControlView'
    licences = ['Apache-2.0']
}

当我删除新创建的类或片段并再次同步项目时,错误消失了,一切恢复正常。这个项目发生了什么事情?
1个回答

1
您需要为constraintLayout移除其中一个依赖项。 使用以下之一: implementation 'androidx.constraintlayout:constraintlayout:1.1.2'implementation 'com.android.support.constraint:constraint-layout:1.0.2'

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接