Android应用程序在同一设备上使用多个APK" ...包与同名的现有包冲突。"

时间:2018-02-09 22:23:38

标签: android android-studio gradle google-play android-manifest

我有一段时间让我们的Android应用程序运行新的构建过程。我希望有两个不同的APK,我可以在同一台设备上并排安装。但是,我收到的错误消息对于处理不同APK配置的人来说似乎很常见。在我安装.debug版本 - "应用程序未安装后,我将安装.release版本的应用程序时,erorr消息如下所示。该程序包与现有程序包的名称相同。"这是我的应用程序的build.gradle文件。

apply plugin: 'com.android.application'

Properties props;
if (project.hasProperty("AndroidProject.signing")
    && new File(project.property("AndroidProject.signing")).exists()) {

props = new Properties()
props.load(new 
FileInputStream(file(project.property("AndroidProject.signing"))))
}

android {
compileSdkVersion 25
buildToolsVersion '26.0.2'
useLibrary 'org.apache.http.legacy'
defaultConfig {
    minSdkVersion 15
    targetSdkVersion 25
    multiDexEnabled true
    versionCode 12
    versionName "2.4"
    ndk {
        abiFilters "armeabi-v7a", "x86", "mips"
    }
}
flavorDimensions "default"
lintOptions {
    abortOnError false
}
signingConfigs {
    release {
        if (props != null) {
            storeFile file(props['STORE_FILE'])
            storePassword props['STORE_PASSWORD']
            keyAlias props['KEY_ALIAS']
            keyPassword props['KEY_PASSWORD']
        } else {
            //Don't sign it with anything. APK will append "unsigned" to itself.
        }
    }
    debug {
        keyAlias 'debug'
        storeFile file('a file path not revealed')
        keyPassword 'debugandroid'
        storePassword 'debugandroid'
    }
}
buildTypes {
    debug {
        debuggable true
        applicationIdSuffix ".debug"
    }
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        if (props != null) {
            signingConfig signingConfigs.release
        }
        debuggable false
        applicationIdSuffix ".release"
    }
}
packagingOptions {
    exclude 'META-INF/LICENSE'
    exclude 'META-INF/LGPL2.1'
    exclude 'META-INF/DEPENDENCIES'
    exclude 'META-INF/LICENSE.txt'
    exclude 'META-INF/license.txt'
    exclude 'META-INF/NOTICE'
    exclude 'META-INF/NOTICE.txt'
    exclude 'META-INF/notice.txt'
    exclude 'META-INF/ASL2.0'
}
compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
}
}


dependencies {
//    implementation 'com.esri.arcgisruntime:arcgis-android:100.2.0'
implementation 'com.esri.arcgis.android:arcgis-android:10.2.9'
implementation project(':lucityREST')
implementation project(':lucityCore')
implementation project(':lucityAndroidCore')
implementation 'com.android.support:support-v4:25.4.0'
}

该项目的一些背景知识。这是从ANT到Gradle的转换。此构建脚本所用的主要应用程序模块位于3个较小的模块之上。我试图解决这个问题的事情。

  1. 发布和调试版本的完全不同的显式applicationIds。

  2. 使用productFlavors并尝试不同的versionCodes,versionNames,applicationIds等

  3. 关闭密钥库只是为了查看它是否存在某种签名问题。目前我有一个不太重要的调试签名,并通过android studio使用生成的密钥库。此外,出于安全目的,我在.properties文件中具有发布密钥库信息,该文件在不同的机器上维护并在项目外部引用(未检入版本控制)。这些构建和应用程序都可以正常工作。

  4. 我已经在Android Studio中生成了.debug和.release APK。包名称使用" applicationIdSuffix"来反映更改。在构建脚本中。

  5. 我还尝试过其他一些小的调整和组织结构的方法,我认为这些结构与讨论无关,或者应该为这个问题负责。

    有谁知道造成这种情况的原因是什么?这是从ANT迁移的可能副作用吗?任何想法或想法将不胜感激。谢谢!

    编辑1:

    这是运行" appt dumb badging"在我的调试apk上。如您所见,包名称反映了已添加.debug后缀。

    package: name='com.lucity.tablet2.debug' versionCode='12' versionName='2.4' platformBuildVersionName=''
    sdkVersion:'15'
    targetSdkVersion:'25'
    uses-permission: name='android.permission.INTERNET'
    uses-permission: name='android.permission.ACCESS_NETWORK_STATE'
    uses-permission: name='android.permission.ACCESS_FINE_LOCATION'
    uses-permission: name='android.permission.ACCESS_COARSE_LOCATION'
    uses-permission: name='android.permission.WRITE_EXTERNAL_STORAGE'
    uses-permission: name='android.permission.READ_PHONE_STATE'
    uses-permission: name='android.permission.ACCESS_WIFI_STATE'
    application-label:'Lucity 2.0 - QA'
    application-icon-160:'res/drawable-hdpi-v4/lucity_launcher.png'
    application-icon-240:'res/drawable-hdpi-v4/lucity_launcher.png'
    application-icon-320:'res/drawable-xhdpi-v4/lucity_launcher.png'
    application-icon-480:'res/drawable-xxhdpi-v4/lucity_launcher.png'
    application: label='Lucity 2.0 - QA' icon='res/drawable-hdpi-v4/lucity_launcher.png'
    application-debuggable
    launchable-activity: name='com.lucity.tablet2.ui.login2.ClientPickerActivity'  label='Lucity 2.0 - QA' icon=''
    uses-permission: name='android.permission.READ_EXTERNAL_STORAGE'
    uses-implied-permission: name='android.permission.READ_EXTERNAL_STORAGE' reason='requested WRITE_EXTERNAL_STORAGE'
    feature-group: label=''
      uses-gl-es: '0x20000'
      uses-feature-not-required: name='android.hardware.location'
      uses-feature-not-required: name='android.hardware.location.gps'
      uses-feature-not-required: name='android.hardware.location.network'
      uses-feature-not-required: name='android.hardware.wifi'
      uses-feature: name='android.hardware.faketouch'
      uses-implied-feature: name='android.hardware.faketouch' reason='default feature for all apps'
      uses-feature: name='android.hardware.screen.landscape'
      uses-implied-feature: name='android.hardware.screen.landscape' reason='one or more activities have specified a landscape orientation'
    main
    other-activities
    other-services
    supports-screens: 'small' 'normal' 'large' 'xlarge'
    supports-any-density: 'true'
    locales: '--_--'
    densities: '160' '240' '320' '480'
    native-code: 'armeabi-v7a' 'x86'
    

3 个答案:

答案 0 :(得分:2)

好的,已经消除了明显的答案,现在是时候去挖掘android的源代码了,这些代码都可以在source.android.com找到。

我发现使用前缀为site:android.googlesource.com的Google搜索最容易做到这一点。因此searching for the error message我们发现此邮件的名称为"install_failed_conflict"。我们希望在java文件中找到它,因此我们搜索"install_failed_conflict" and java并且只要PackageInstaller.STATUS_FAILURE_CONFLICT找到InstallAppProgress就会出现此错误。然后我们搜索STATUS_FAILURE_CONFLICT(如果您的IDE中有android源代码会更快),并发现PackageManager实际上使用this code for lots of things

  • 已经存在(显然),但也
  • INSTALL_FAILED_UPDATE_INCOMPATIBLE
  • INSTALL_FAILED_SHARED_USER_INCOMPATIBLE
  • INSTALL_FAILED_REPLACE_COULDNT_DELETE
  • INSTALL_FAILED_CONFLICTING_PROVIDER
  • INSTALL_FAILED_DUPLICATE_PERMISSION

我并不确切知道所有这些意味着什么(但我可以继续查看源代码以查找),但是其中一个可能适用于您的APK吗?也许重复许可?

我的最高猜测是this code,我想知道您的调试包和发布包是否存在冲突的提供商?

答案 1 :(得分:1)

Android应用程序由包名称标识,例如com.foo.bar。您一次只能在设备上安装一个具有给定包名称的应用程序。如果您希望将发布和调试版本安装在同一设备上,则需要为它们提供不同的软件包名称,例如com.foo.barcom.foo.bar.debug

在gradle中,这称为applicationId

您的gradle文件中的applicationIdSuffix设置似乎没有正确的效果。

如果您在APK上使用带有命令行aapt dump badging的aapt工具,您可以看到哪个包名实际上正在写入您的APK,并且可能会看到问题所在,因为它看起来像后缀isn& #39;正在使用。

答案 2 :(得分:0)

Android是linux基础系统,每个应用程序都像新用户,不同用户不允许使用相同的应用程序ID。因此,要更改同一个应用程序的ID,如登台和生产应用程序。 您可以在gradle中添加构建类型

android {                                                    
    buildTypes {
    release {
        resValue "string", "app_name", "App"
        buildConfigField "boolean", "is_prod", "true"
    }
    debug {
        applicationIdSuffix ".debug"
        resValue "string", "app_name", "App staging"
        buildConfigField "boolean", "is_prod", "false"
    }
  }                                                                      
}                                                                                   

比.debug将在包名中添加。

相关问题