简体   繁体   English

使用APK Splits for Release但不使用Debug构建类型

[英]Using APK Splits for Release but not Debug build type

I've successfully implemented APK Splits so that separate APKs are generated for different ABIs. 我已成功实施APK Splits,以便为不同的ABI生成单独的APK。

However, for efficiency (and since I have no need for non-armeabi-v7a APKs in Debug), I would like to limit Debug builds to only generate armeabi-v7a APKs. 但是,为了提高效率(因为我在调试中不需要非armeabi-v7a APK),我想限制Debug版本只生成armeabi-v7a APK。

How can this be done? 如何才能做到这一点?

One idea is with this: 一个想法是这样的:

abi {
    enable true
    reset()
    include 'x86', 'armeabi-v7a', 'mips'
    universalApk false
}

Maybe there is some way to set enable based on the Build type? 也许有一些方法enable根据Build类型设置enable

You can try a variation on @Geralt_Encore's answer, which avoids the separate gradlew command. 您可以尝试@ Geralt_Encore的答案的变体,这避免了单独的gradlew命令。 In my case, I only cared to use APK splitting to reduce the released APK file size, and I wanted to do this entirely within Android Studio. 在我的情况下,我只关心使用APK拆分来减少已发布的APK文件大小,我想在Android Studio中完全执行此操作。

splits {
    abi {
      enable gradle.startParameter.taskNames.any { it.contains("Release") }
      reset()
      include 'x86', 'armeabi-v7a', 'mips'
      universalApk false
    }
}

From what I've seen, the Build | 从我所见,Build | Generate Signed APK menu item in Android Studio generates the APK using the assembleRelease Gradle target. 在Android Studio中生成签名的APK菜单项使用assembleRelease Gradle目标生成APK。

You can set enable based on command line argument. 您可以根据命令行参数设置enable I have solved kinda similar problem when I wanted to use splits only for the release version, but not for regular debug builds. 当我只想为发布版本使用拆分时,我已经解决了类似的问题,但不适用于常规的调试版本。

splits {
    abi {
        enable project.hasProperty('splitApks')
        reset()
        include 'x86', 'armeabi-v7a'
    }
}

And then ./gradlew -PsplitApks assembleProdRelease (prod is a flavor in my case). 然后./gradlew -PsplitApks assembleProdRelease (在我的情况下prod是一种味道)。

I'm a bit late to this party, but having a problem with different flavors and tasks names, I've come with this: 我参加这个派对有点晚了,但是对于不同的口味和任务名称有问题,我来这里:

ext.isRelease = { array ->
    array.each { name ->
        if (name.contains("Debug")) {
            return false
        }
    }
    return true
}

android {

...

    splits {
        abi {
            enable isRelease(gradle.startParameter.taskNames)
            reset()
            include "x86_64", "x86", "arm64-v8a", "armeabi-v7a"
            universalApk false
        }
    }

}

It's just a small update to Jeff P's answer but works well with different flavors and build configurations. 这只是Jeff P的答案的一个小小的更新,但适用于不同的风格和构建配置。

Update for @Jeff P 's answer to make it more flexible based on app name and to support Android App Bundle (.aab) format 更新@Jeff P的答案,根据应用名称使其更加灵活,并支持Android App Bundle(.aab)格式

splits {
    abi {
      enable gradle.startParameter.taskNames.any { it.contains("Release") }
      reset()
      include 'x86', 'armeabi-v7a', 'mips'
      universalApk false
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Android WorkManager使用调试版本,但不能使用版本APK - Android WorkManager working with debug build but not with release APK Nativescript在构建版本上失败,在debug.apk上成功完成apk - Nativescript failed on build release apk success on debug.apk 使用 chrome 开发工具调试发布 apk - Debug release apk using chrome dev tools Meteor build仅为Crosswalk项目生成调试apk(不发布) - Meteor build generate only debug apk (not release) for project with Crosswalk Qt Android:为什么为Release版本创建了QtApp-debug.apk? - Qt Android: Why is a QtApp-debug.apk created for a Release build? 调试正常时无法构建发布 APK flutter - Can't build release APK flutter when debug is fine Ionic cordova build android –prod –release 只构建一个调试apk (app-debug.apk) - Ionic cordova build android –prod –release only builds a debug apk (app-debug.apk) 如何使用maven在发布模式下构建apk - How to build apk in release mode using maven 使用发布构建类型构建 android studio 签名的 apk - Build android studio signed apk with release build type Android:在Android Studio中生成调试版本apk和发布版本apk的过程 - Android: Procedure for Generating Debug build apk's and Release build apk's in Android Studio
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM