错误:程序类型已经存在:androidx.versionedparcelable.ParcelImpl

6
我正在尝试添加这个https://github.com/ArthurHub/Android-Image-Cropper,但是当我添加时,我遇到了这个错误:“Error: Program type already present: androidx.versionedparcelable.ParcelImpl”。 我已经附上了项目 gradle 和 app gradle。(我是 Android 开发的新手,不太确定如何修复。) 我认为可能与以下内容有关。
implementation "com.android.support:appcompat-v7:${supportLibVersion}"
implementation "com.android.support:design:${supportLibVersion}"

但是这些代码是用于我一个活动中的TextInputLayout。任何帮助都将不胜感激。

  // Top-level build file where you can add configuration options common to all sub-projects/modules.

    buildscript {

        repositories {
            google()
            jcenter()
        }
        dependencies {
            classpath 'com.android.tools.build:gradle:3.2.1'
            classpath 'com.google.gms:google-services:4.0.0'

            // NOTE: Do not place your application dependencies here; they belong
            // in the individual module build.gradle files
        }
    }

    allprojects {
        repositories {
            google()
            jcenter()
            maven{
               url  "https://maven.google.com"
            }
        }
    }

    task clean(type: Delete) {
        delete rootProject.buildDir
    }

应用Gradle:

apply plugin: 'com.android.application'

    android {
        compileSdkVersion 28
        defaultConfig {
            applicationId "com.something.app"
            minSdkVersion 24
            targetSdkVersion 28
            versionCode 1
            versionName "1.0"
            testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        }
        buildTypes {
            release {
                minifyEnabled false
                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            }
        }
    }

        ext {
            supportLibVersion = '27.1.1'  // variable that can be referenced to keep support libs consistent
            }

    dependencies {

        api 'com.theartofdev.edmodo:android-image-cropper:2.8.+'

        implementation "com.android.support:appcompat-v7:${supportLibVersion}"
        implementation "com.android.support:design:${supportLibVersion}"
        implementation fileTree(dir: 'libs', include: ['*.jar'])
        implementation 'com.android.support:appcompat-v7:28.0.0-rc01'
        implementation 'com.android.support:design:28.0.0-rc01'
        implementation 'com.android.support.constraint:constraint-layout:1.1.3'
        implementation 'com.google.firebase:firebase-core:16.0.4'
        implementation 'com.google.firebase:firebase-auth:16.0.4'
        implementation 'com.google.firebase:firebase-database:16.0.3'
        implementation 'com.google.firebase:firebase-storage:16.0.3'
        testImplementation 'junit:junit:4.12'
        implementation 'de.hdodenhof:circleimageview:2.2.0'
        implementation 'com.squareup.picasso:picasso:2.71828'
        implementation 'com.android.support:support-v4:28.0.0'
        androidTestImplementation 'com.android.support.test:runner:1.0.2'
        androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
        implementation 'com.android.support:design:28.0.0-rc01'



        //implementation 'com.google.android.gms:play-services-maps:16.0.0'
        // implementation 'com.google.android.gms:play-services-analytics:7.3.0'
        implementation 'com.google.android.gms:play-services-maps:16.0.0'
        implementation 'com.google.android.gms:play-services-location:16.0.0'
        implementation 'com.google.android.gms:play-services-analytics:16.0.4'
        implementation 'com.google.android.gms:play-services-places:16.0.0'
    }

    apply plugin: 'com.google.gms.google-services'

尝试将api 'com.theartofdev.edmodo:android-image-cropper:2.8.+'替换为implementation 'com.theartofdev.edmodo:android-image-cropper:2.8.0' - punchman
5个回答

7
您正在使用支持库,而新版本的Image-Cropper库使用androidx库。
请查看变更日志
因此,您有两个选择,要么迁移到androidx,要么将库版本更改为旧版本。 api 'com.theartofdev.edmodo:android-image-cropper:2.7.0'

谢谢你。这解决了我的问题。我在应用兼容库上遇到了问题,需要使用一个旧的库来代替它。 - SaundersB

4

我通过将ButterKnife依赖项降级到8.8.1版本来解决了我的问题。

// BUTTERKNIFE
implementation 'com.jakewharton:butterknife:8.8.1'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'

另一种解决方法是在整个项目文件中搜索使用androidx的任何导入语句,然后将其替换为android.support版本。

在我的情况下,我发现了 -

import androidx.annotation.NonNull; 我将其替换为 import android.support.annotation.NonNull;


1

您可以保留最新版本并配置gradle以使用AndroidX

api 'com.theartofdev.edmodo:android-image-cropper:2.8.+'

gradle.properties:

android.useAndroidX=true
android.enableJetifier=true

来自文档使用 AndroidX

请参阅《迁移到 AndroidX》以了解如何将现有项目迁移到 AndroidX。

如果您想在新项目中使用 AndroidX,则需要将编译 SDK 设置为 Android 9.0(API 级别 28)或更高,并在 gradle.properties 文件中将以下两个 Android Gradle 插件标志都设置为 true。

android.useAndroidX:当设置为 true 时,Android 插件将使用适当的 AndroidX 库而不是支持库。如果未指定该标志,则默认情况下该标志为 false。

android.enableJetifier:当设置为 true 时,Android 插件会自动将现有的第三方库迁移到 AndroidX,通过重写其二进制文件。如果未指定该标志,则默认情况下该标志为 false。


0

你需要使用api 'com.theartofdev.edmodo:android-image-cropper:2.7.0'

因为android-image-cropper:2.8.+'已经更新到支持库AndroidX

对于com.android.support,请使用此方法

api 'com.theartofdev.edmodo:android-image-cropper:2.7.0'

对于 AndroidX,请使用这个。
api 'com.theartofdev.edmodo:android-image-cropper:2.8.+'

变更日志 2.8.0

  • 修复 Android O 上的崩溃问题

  • 更新支持库至 AndroidX

  • 处理选择非图像文件时的失败情况

  • 增加更多翻译

如需更多信息,请阅读 Android Image Cropper 的变更日志


0

如果您已添加了模型裁剪器,请将其删除并添加

对于com.android.support,请使用此方法

api 'com.theartofdev.edmodo:android-image-cropper:2.7.0'

关于 AndroidX,请使用以下内容

api 'com.theartofdev.edmodo:android-image-cropper:2.8.+'

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接