【问题标题】:Android 65k multidex issue for android system applicationAndroid系统应用程序的Android 65k multidex问题
【发布时间】:2016-08-20 14:07:03
【问题描述】:

开发与多个库和 aar 文件一起使用的系统应用程序导致应用程序遇到 Multidex 65k 问题,许多开发 Android Studio 的开发人员报告了该问题。 在我的情况下,我正在研究 android 系统构建环境,不确定如何启用 multidex 选项?

扩展了应用程序并添加了 MultiDex.install(this);这对编译结果没有影响

写入输出问题:方法引用过多:156862;最大值为 65536。 您可以尝试使用 --multi-dex 选项。

找不到针对此类问题的系统构建工作的任何参考。

对此的任何指示都会有所帮助

谢谢

【问题讨论】:

  • 感谢您的回复。我面临的问题与不在 Android Studio 中的 android 系统应用程序开发有关。已经在我没有看到 multidex 错误的 Android Studio 应用程序开发中应用了共享 cmets。但是这个问题出现在 Android 系统开发中,因为我们在这个开发环境中没有 gradle 文件。让我知道是否需要任何澄清?

标签: android android-multidex


【解决方案1】:

在你的 gradle 中更新

 defaultConfig {
  ..............

multiDexEnabled true


}

dexOptions 应该添加..

dexOptions {
   //incremental = true;
preDexLibraries = false
javaMaxHeapSize "4g"
 }

依赖添加

 compile 'com.android.support:multidex:1.0.1'

也在你的 AndroidManifest.xml 添加这行 android:name

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme"
android:name="android.support.multidex.MultiDexApplication"
>

【讨论】:

  • preDexLibraries=false 在我的情况下单独做到了。谢谢!
【解决方案2】:

想法是如果apk方法> 64K,那么我们打破它有多个dex文件。

build.gradle

android {

    defaultConfig {

        ...

        // Enabling multidex support.
        multiDexEnabled true
    }
    ...
}

dependencies {
  // Add this dependency 
  compile 'com.android.support:multidex:1.0.0'
}

希望这会有所帮助。

参考:Android Dev

【讨论】:

    【解决方案3】:

    您可以访问Configure Apps with Over 64K Methods了解详情。

    这里有一些摘录:

    将您的应用开发项目设置为使用 multidex 配置需要您对应用开发项目进行一些修改。特别是您需要执行以下步骤:

    • 更改您的 Gradle 构建配置以启用 multidex
    • 修改清单以引用 MultiDexApplication 类

    修改模块级别的build.gradle文件配置,包含支持库并启用multidex输出,如下代码sn -p所示:

    android {
        compileSdkVersion 21
        buildToolsVersion "21.1.0"
    
        defaultConfig {
            ...
            minSdkVersion 14
            targetSdkVersion 21
            ...
    
            // Enabling multidex support.
            multiDexEnabled true
        }
        ...
    }
    
    dependencies {
      compile 'com.android.support:multidex:1.0.0'
    }
    

    在您的清单中,将 MultiDexApplication 类从 multidex 支持库添加到应用程序元素。

    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
        package="com.example.android.multidex.myapplication">
        <application
            ...
            android:name="android.support.multidex.MultiDexApplication">
            ...
        </application>
    </manifest>
    

    更新

    如果您已包含 Google Play 服务库,请改为使用:

    compile 'com.google.android.gms:play-services:9.4.0'
    

    尽量只使用你真正需要的东西。像这样的:

    com.google.android.gms:play-services-base:9.4.0
    com.google.android.gms:play-services-ads:9.4.0 // only need ads
    com.google.android.gms:play-services-gcm:9.4.0 // only need gcm
    

    Setting Up Google Play Services了解更多信息。

    【讨论】:

    • 感谢您的回复。我面临的问题与不在 Android Studio 中的 android 系统应用程序开发有关。已经在我没有看到 multidex 错误的 Android Studio 应用程序开发中应用了共享 cmets。但是这个问题出现在 Android 系统开发中,因为我们在这个开发环境中没有 gradle 文件。让我知道是否需要任何澄清?
    • 你能解释一下你的But the issue is seen in Android system development as we dont have gradle files in this development environment 的话吗?这是不是说明你没用过gradle?
    • 我所说的“Android 系统开发”是指通过 repo 同步命令 -source.android.com/source/downloading.html 下载代码,其中会下载完整的操作系统源代码。正在研究要包含在此环境中的应用程序。他们不是 GRADLE 就是这些完整的源代码。希望现在能够在android系统环境中清楚地解释问题。不使用 Android Studio IDE 进行开发。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-04-16
    • 1970-01-01
    • 1970-01-01
    • 2014-12-25
    • 2015-03-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多