问题
some errors after migration to AndroidX
I downloaded LeafPic-master project( it is a gallery source code for Android studio)and try to change minsdkversion and targetSdkVersion( I want to install my app on android 4.4 to newest android api).So I add the google()
repo in the repositories
to solve some problems then migrate to AndroidX.
the list of my errors is:
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
and my Build.gradle is:
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'
}
other Errors is:
cannot resolve symbole 'material'
cannot resolve symbole 'appcompat'
cannot resolve symbole 'cardview'
cannot resolve symbole 'recyclerview'
in this lines:
import com.google.android.material.floatingactionbutton.FloatingActionButton;
import androidx.appcompat.app.ActionBarDrawerToggle;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.widget.Toolbar;
import androidx.appcompat.widget.SwitchCompat;
import androidx.cardview.widget.CardView;
import androidx.recyclerview.widget.DefaultItemAnimator;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
回答1:
try to change
sourceCompatibility JavaVersion.VERSION_1_6
targetCompatibility JavaVersion.VERSION_1_6
to
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
回答2:
This can be a gradle issue.
Consider deleting gradle cache and retrying.
Gradle cache is at C:\Users\yourUserName\.gradle\caches
(windows) or ~/.gradle/caches
(linux)
Note: If your area is under sanction, you must bypass this using proxy or VPN.
回答3:
At first, there is no need to inject the recyclerView's, CardView's and material libraries into the gradle file because in the android studio i.e. 3.4 and above all these libraries are already inserted by default. Just replace your this library -> implementation 'com.android.support:appcompat-v7:28.0.0' with implementation 'androidx.appcompat:appcompat:1.1.0' and plus, go into the gradle.properties file and add this line -> "android.useAndroidX=true" and your project will work fine. In my case it worked.
来源:https://stackoverflow.com/questions/58075940/some-errors-after-migration-to-androidx