【问题标题】:Android application is not working in lower version like GingerbreadAndroid 应用程序无法在 Gingerbread 等较低版本中运行
【发布时间】:2015-09-30 06:36:49
【问题描述】:

我正在尝试开发一个适用于所有 android 版本(如 API 级别 23 和 API 级别 8)的应用程序。在调试应用程序时,它在最新版本的 api 上运行良好,但不适用于 Gingerbread 等较低版本。

我尝试更改minSdkVersion,但这并没有解决问题。

在低版本调试时显示错误

“安装失败,因为设备可能有陈旧的 dexed jars 与当前版本不匹配(dexopt 错误)。为了 继续,您必须卸载现有的应用程序。”

Build.gradle

apply plugin: 'android'

dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
compile 'com.google.android.gms:play-services:7.8.0'
compile 'com.android.support:appcompat-v7:22.0.0'
compile 'com.android.support:support-v4:21.0.3'
}
android {
compileSdkVersion 22
buildToolsVersion "21.0.0"

defaultConfig {
    applicationId "org.linphone"
    minSdkVersion 9
    targetSdkVersion 22
    versionCode 1
    versionName "1.0"
}

sourceSets {

    debug.setRoot('build-types/debug')
    release.setRoot('build-types/release')
 }
android {
    defaultConfig {
        multiDexEnabled = true
        minSdkVersion
        targetSdkVersion
    }
}

configurations.all {
    exclude group: 'com.android.support', module: 'support-annotations'
}
}

Manifest.xml

    <uses-sdk
    android:minSdkVersion="9"
      />

【问题讨论】:

  • 显示堆栈跟踪!
  • 安装 org.linphone DEVICE SHELL 命令:pm install -r "/data/local/tmp/org.linphone" pkg: /data/local/tmp/org.linphone 失败 [INSTALL_FAILED_DEXOPT] DEVICE SHELL命令:pm uninstall org.linphone 未知故障@Anggrayudi H
  • 您是否尝试过清除应用数据并手动卸载?
  • 该应用程序尚未安装在“Gingerbread”中,正在尝试安装在“Gingerbread”中。所以...

标签: android android-studio gradle android-gradle-plugin build.gradle


【解决方案1】:

您正在使用 gradle,因此您应该从 manifest.xml 中删除 uses-sdk 声明 - gradle 会自行添加它。然后将 build.gradle 中的 minSdkVersion 更改为等于或低于您想要的值。

【讨论】:

  • 我从 manifest.xml 中删除了 uses-sdk 声明。但它仍然没有运行,它显示“安装失败,因为设备可能有与当前版本不匹配的陈旧 dexed jar(dexopt 错误)。为了继续,您必须卸载现有的应用程序。” @piotrpo
  • 你的系统版本是什么(你在 gradle 有 9,但​​你问的是 8?
  • 该应用程序在冰淇淋三明治以下的版本中无法运行。GingerBread API 为 10,我尝试将其安装在 GingerBread 中但它无法运行@piotrpo
【解决方案2】:

启用你的proguard,它可能是由dex文件引起的。当 dex 文件变得大于缓冲区大小时会发生这种情况(即包含超过 65k 的方法)。

android {
    ...

    buildTypes {
        release {
            minifyEnabled true
            shrinkResources true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

【讨论】:

    【解决方案3】:

    您的应用已达到 65k 方法限制。解决方案很少:

    1. 使用ProGuard 收缩您的代码。来自文档:

    ProGuard 工具通过删除未使用的代码并用语义模糊的名称重命名类、字段和方法来缩小、优化和混淆您的代码。结果是较小的 .apk 文件更难进行逆向工程。因为 ProGuard 使您的应用程序更难进行逆向工程,所以当您的应用程序使用对安全性敏感的功能时使用它很重要,例如当您是 Licensing Your Applications 时。

    在您的app 模块的build.gradle 上启用它:

    buildTypes {
        release {
            minifyEnabled true
            shrinkResources true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
        debug {
            minifyEnabled true
            shrinkResources true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    

    您可以添加自己的 ProGuard 自定义规则,read here

    1. 将 SDK 构建工具更新到最新版本。

    2. 使用MultiDex technique 构建您的应用程序。

    此外,您的apply plugin: 'android' 必须更改为apply plugin: 'com.android.application'

    【讨论】:

      【解决方案4】:

      我在模拟器上测试时遇到了这个问题。我的解决方案是给模拟器更多的内存和存储空间。在使用新 (ART) 工具构建并部署到 Dalvik 时,这似乎是一个问题。

      【讨论】:

        猜你喜欢
        • 2013-10-16
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-07-22
        • 1970-01-01
        • 2015-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多