android - 当min sdk为5.0以下时,启用multidex创建singledex,而当min sdk为5.0以上时,则启用multidex。

标签 android gradle android-5.0-lollipop android-multidex

当最小sdk低于5.0时启用multidex创建singledex
但是,当min sdk为5.0及更高版本时,它将创建多个dex文件。

重现步骤:

  • 创建项目并添加appcompat和RecyclerView库
  • 将min sdk设置为14并构建项目
    输出:将在构建文件夹
  • 中创建单个dex。
  • 将min sdk设置为21并构建项目
    输出:将在构建文件夹
  • 中创建多个dex文件

    在5.0及更高版本中未达到64k限制时,有什么方法可以避免创建多个dex?

    最佳答案

    您需要禁用InstantRun来禁用multidex,因为如果最小sdk设置为21或更高,则会自动配置它。

    您可以从documentation读取它:

    Multidex support for Android 5.0 and higher
    Android 5.0 (API level 21) and higher uses a runtime called ART which natively supports loading multiple DEX files from APK files. ART performs pre-compilation at app install time which scans for classesN.dex files and compiles them into a single .oat file for execution by the Android device. Therefore, if your minSdkVersion is 21 or higher, you do not need the multidex support library.

    For more information on the Android 5.0 runtime, read ART and Dalvik.

    Note: While using Instant Run, Android Studio automatically configures your app for multidex when your app's minSdkVersion is set to 21 or higher. Because Instant Run only works with the debug version of your app, you still need to configure your release build for multidex to avoid the 64K limit.

    关于android - 当min sdk为5.0以下时,启用multidex创建singledex,而当min sdk为5.0以上时,则启用multidex。,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46603037/

    相关文章:

    Android:检测请勿打扰状态?

    android - CardView 都相互堆叠

    android - 全屏 YouTube 播放器中隐藏在系统 UI 下的工具栏叠加层

    java - Android:无法实例化应用程序

    java - 如何在 Android 中的两个图像之间放置文本

    android studio为模块添加.aar依赖而不生成其他.gradle文件

    flutter - 无法解析配置的所有工件

    gradle - 如何修复Tavis构建中的权限被拒绝问题

    android - Lollipop 设置默认本地不起作用

    android - 不在 ListView 中滚动时自动隐藏滚动条