![](/img/trans.png)
[英]Unable to resolve dependency for ':app@debug/compileClasspath': Could not resolve project
[英]Unable to resolve dependency for ':app@debug/compileClasspath': Could not resolve androidx
我正在使用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']
}
當我刪除新創建的類或片段並再次同步項目時,錯誤消失了,一切恢復正常,項目發生了什么?
您有2個ConstraintLayout依賴項。 刪除其中之一。 使用implementation 'androidx.constraintlayout:constraintlayout:1.1.2'
或implementation 'com.android.support.constraint:constraint-layout:1.0.2'
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.