迁移到AndroidX后的一些错误
我下载了LeafPic-master项目(这是Android Studio的图库源代码),并尝试更改minsdkversion和targetSdkVersion(我想将我的应用程序在android 4.4上安装到最新的android api)。所以我添加了{{1 }}在google()
中进行回购以解决一些问题,然后迁移到AndroidX。
我的错误列表是:
repositories
而我的Build.gradle是:
ERROR: Failed to resolve: androidx.recyclerview:recyclerview:1.0.0
Show in Project Structure dialog
Affected Modules: app
ERROR: Failed to resolve: com.google.android.material:material:1.0.0
Show in Project Structure dialog
Affected Modules: app
ERROR: Failed to resolve: androidx.palette:palette:1.0.0
Show in Project Structure dialog
Affected Modules: app
ERROR: Failed to resolve: androidx.legacy:legacy-support-v4:1.0.0
Show in Project Structure dialog
Affected Modules: app
ERROR: Failed to resolve: androidx.browser:browser:1.0.0
Show in Project Structure dialog
Affected Modules: app
ERROR: Failed to resolve: androidx.exifinterface:exifinterface:1.0.0
Show in Project Structure dialog
Affected Modules: app
ERROR: Failed to resolve: com.google.android.gms:play-services-iid:[17.0.0]
Show in Project Structure dialog
Affected Modules: app
ERROR: Failed to resolve: androidx.vectordrawable:vectordrawable-animated:1.0.0
Show in Project Structure dialog
Affected Modules: app
ERROR: Failed to resolve: fragment
Affected Modules: app
其他错误是:
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.0'
}
}
apply plugin: 'com.android.application'
repositories {
google()
jcenter()
maven { url "http://repo1.maven.org/maven2" }
maven { url "http://dl.bintray.com/dasar/maven" }
maven { url 'https://maven.google.com' }
}
android {
compileSdkVersion 29
buildToolsVersion '27.0.3'
defaultConfig {
minSdkVersion 15
targetSdkVersion 29
versionCode 1
versionName "1.0.0"
vectorDrawables.useSupportLibrary = true
}
lintOptions {
disable 'MissingTranslation'
disable 'ExtraTranslation'
}
// This is handled for you by the 2.0+ Gradle Plugin
aaptOptions {
additionalParameters "--no-version-vectors"
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_6
targetCompatibility JavaVersion.VERSION_1_6
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'androidx.vectordrawable:vectordrawable:1.0.1'
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'androidx.recyclerview:recyclerview:1.0.0'
implementation 'com.google.android.material:material:1.0.0'
implementation 'androidx.palette:palette:1.0.0'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'androidx.browser:browser:1.0.0'
implementation "androidx.exifinterface:exifinterface:1.0.0"
implementation "androidx.appcompat:appcompat:1.0.0"
implementation 'com.github.bumptech.glide:glide:4.9.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.9.0'
implementation 'com.koushikdutta.ion:ion:2.1.7'
implementation 'com.mikepenz:iconics-core:3.0.3@aar'
implementation 'com.mikepenz:google-material-typeface:3.0.1.2.original@aar'
implementation 'com.mikepenz:community-material-typeface:2.0.46.1@aar'
implementation 'com.mikepenz:fontawesome-typeface:4.7.0.2@aar'
implementation "com.mikepenz:iconics-views:3.0.3@aar"
implementation 'com.github.paolorotolo:appintro:3.4.0'
implementation 'com.yalantis:ucrop:1.5.0'
implementation 'uz.shift:colorpicker:0.5@aar'
implementation 'com.balysv:material-ripple:1.0.2'
implementation 'com.commit451:PhotoView:1.2.5'
implementation 'com.google.android.exoplayer:exoplayer:r1.5.7'
implementation 'de.psdev.licensesdialog:licensesdialog:1.8.3'
implementation 'com.davemorrissey.labs:subsampling-scale-image-view:3.10.0'
implementation 'de.hdodenhof:circleimageview:2.2.0'
implementation 'com.drewnoakes:metadata-extractor:2.11.0'
implementation 'org.jetbrains:annotations-java5:15.0'
implementation 'co.ronash.android:pushe-base:1.3.3'
api 'com.google.android.gms:play-services-gcm:17.0.0'
}
在此行:
cannot resolve symbole 'material'
cannot resolve symbole 'appcompat'
cannot resolve symbole 'cardview'
cannot resolve symbole 'recyclerview'
答案 0 :(得分:0)
尝试更改
sourceCompatibility JavaVersion.VERSION_1_6
targetCompatibility JavaVersion.VERSION_1_6
到
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
答案 1 :(得分:0)
这可能是一个问题。
考虑删除gradle缓存并重试。
Gradle缓存位于C:\Users\yourUserName\.gradle\caches
(Windows)或~/.gradle/caches
(Linux)
注意::如果您所在的区域受到制裁,则必须使用代理或VPN绕过该攻击。
答案 2 :(得分:0)
首先,无需将recyclerView,CardView和物料库注入gradle文件中,因为在android studio中,即3.4及更高版本中,默认情况下已插入所有这些库。只需将您的库->实现'com.android.support:appcompat-v7:28.0.0'替换为实现'androidx.appcompat:appcompat:1.1.0',然后将其放入gradle.properties文件并添加以下行->“ android.useAndroidX = true”,您的项目将正常运行。就我而言,它奏效了。
答案 3 :(得分:0)
将此代码添加到build gradle
android {
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}