无法解析':app @ debug / compileClasspath'的依赖项:无法解析androidx

时间:2018-08-12 08:40:26

标签: android android-studio

我正在使用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);
        }
    }

您可以看到以下行:

导入androidx.appcompat.app.AppCompatActivity;

appcompat 是红色

而所有旧类都改为以下行:

导入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
}

还有一个包含主要项目的图书馆项目,最主要的是:

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 个答案:

答案 0 :(得分:0)

您有2个ConstraintLayout依赖项。删除其中之一。 采用 implementation 'androidx.constraintlayout:constraintlayout:1.1.2' 要么 implementation 'com.android.support.constraint:constraint-layout:1.0.2'