【问题标题】:some Errors after migration to AndroidX迁移到 AndroidX 后的一些错误
【发布时间】:2020-08-13 23:23:20
【问题描述】:

迁移到 AndroidX 后的一些错误

我下载了 LeafPic-master 项目(它是 Android 工作室的图库源代码)并尝试更改 minsdkversion 和 targetSdkVersion(我想在 android 4.4 上安装我的应用程序到最新的 android api)。所以我添加了 google() repositories 中的 repo 以解决一些问题,然后迁移到 AndroidX。 我的错误列表是:

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

我的 Build.gradle 是:

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'

在这行:

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;

【问题讨论】:

  • 我不是专家,就像你过去不是专家一样。我是初学者,我知道问总比不知道好

标签: android build.gradle


【解决方案1】:

尝试改变

sourceCompatibility JavaVersion.VERSION_1_6
targetCompatibility JavaVersion.VERSION_1_6

sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8

【讨论】:

    【解决方案2】:

    这可能是一个 gradle 问题。

    考虑删除 gradle 缓存并重试。

    Gradle 缓存位于 C:\Users\yourUserName\.gradle\caches (windows) 或 ~/.gradle/caches (linux)

    注意:如果您所在的地区受到制裁,您必须使用代理或 VPN 绕过此限制。

    【讨论】:

      【解决方案3】:

      首先,不需要将recyclerView、CardView和材料库注入到gradle文件中,因为在android studio即3.4及以上版本中,所有这些库都已经默认插入。只需将您的这个库 - > implementation 'com.android.support:appcompat-v7:28.0.0' 替换为 implementation 'androidx.appcompat:appcompat:1.1.0' ,然后进入 gradle.properties 文件并添加这一行->“android.useAndroidX=true”,你的项目就可以正常工作了。就我而言,它有效。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2019-04-09
        • 1970-01-01
        • 1970-01-01
        • 2019-11-02
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多