【问题标题】:Error: Program type already present: androidx.versionedparcelable.ParcelImpl错误:程序类型已经存在:androidx.versionedparcelable.ParcelImpl
【发布时间】:2019-04-05 07:40:45
【问题描述】:

我正在尝试添加此 https://github.com/ArthurHub/Android-Image-Cropper 但当我添加它时,我收到此错误“错误:程序类型已存在:androidx.versionedparcelable.ParcelImpl”

我已附加项目 gradle 和应用程序 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'

标签: android gradle compiler-errors androidx


【解决方案1】:

您使用支持库,而新版本的 Image-Cropper 库使用 androidx 库。

检查change log

所以,您有两个选择,您可以移动到 androidx 或将库版本更改为旧版本

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

【讨论】:

  • 谢谢你。这解决了我的问题。我遇到了应用兼容库的问题,需要使用较旧的库。
【解决方案2】:

我通过将黄油刀依赖项降级到版本 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;

【讨论】:

    【解决方案3】:

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

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

    gradle.properties:

    android.useAndroidX=true
    android.enableJetifier=true
    

    来自文档Using AndroidX

    请参阅迁移到 AndroidX,了解如何迁移现有项目。

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

    android.useAndroidX:设置为 true 时,Android 插件使用 适当的 AndroidX 库而不是支持库。国旗是 不指定则默认为false。

    android.enableJetifier: 什么时候 设置为 true,Android 插件会自动迁移现有的 第三方库通过重写其二进制文件来使用 AndroidX。这 如果不指定flag,默认为false。

    【讨论】:

      【解决方案4】:

      你需要使用 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的Change log

      【讨论】:

        【解决方案5】:

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

        对于 com.android.support 使用这个

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

        对于 AndroidX 使用这个

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

        【讨论】:

          猜你喜欢
          • 2019-05-26
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2018-09-23
          • 2019-02-22
          • 1970-01-01
          • 2018-10-21
          相关资源
          最近更新 更多