美文网首页
Android 打包

Android 打包

作者: 乘风破浪的程序员 | 来源:发表于2019-05-31 17:03 被阅读0次

    1: JNI 分割打包不同cpu

    gradle android下添加:

    sourceSets {
        main {
            jniLibs.srcDirs = ['libs']
        }
    }
    splits {
        abi {
            enable true
            reset()
            include 'armeabi-v7a','arm64-v8a','x86','x86_64'
            universalApk true
        }
    }
    

    2: 多渠道打包

       flavorDimensions "default"
    
        productFlavors {
            free {
                dimension "default"
                buildConfigField "boolean", "isPro", "false" 
            }
            pro {
                dimension "default"
                applicationIdSuffix ".pro"
                buildConfigField "boolean", "isPro", "true" 
            }
           china { 
                dimension "default"
                applicationIdSuffix ".pro"
                buildConfigField "boolean", "isPro", "false" 
            }
            adInject {  
                applicationIdSuffix ".pro"
                buildConfigField "boolean", "isPro", "false" 
            }
        }
    

    3: 解决pipeline 打包不同平台apk 问题
    Error:

    `* What went wrong:`
    
    `Execution failed for task ':app:publishReleaseApk'.`
    
    `> com.google.api.client.googleapis.json.GoogleJsonResponseException: 403 Forbidden`
    
    `{`
    
    `"code" : 403,`
    
    `"errors" : [ {`
    
    `"domain" : "androidpublisher",`
    
    `Deprecated Gradle features were used in this build, making it incompatible with Gradle 6.0.`
    
    `Use '--warning-mode all' to show the individual deprecation warnings.`
    
    `See [https://docs.gradle.org/5.1.1/userguide/command_line_interface.html#sec:command_line_warnings](https://docs.gradle.org/5.1.1/userguide/command_line_interface.html#sec:command_line_warnings)`
    
    `"message" : "Version 1207 of this app cannot be downloaded by any devices as they will all receive APKs with higher version codes.",`
    
    `"reason" : "fullyShadowed"`
    
    `} ],`
    
    `"message" : "Version 1207 of this app cannot be downloaded by any devices as they will all receive APKs with higher version codes."`
    
    `}`
    
    
    
    // map for the version code
    ext.abiCodes = ['arm64-v8a': 4, 'armeabi-v7a': 3, 'x86_64': 2, 'x86': 1, 'universal': 0]
    
    import com.android.build.OutputFile
    
    // For each APK output variant, override versionCode with a combination of
    // ext.abiCodes * 1000 + variant.versionCode. In this example, variant.versionCode
    // is equal to defaultConfig.versionCode. If you configure product flavors that
    // define their own versionCode, variant.versionCode uses that value instead.
    android.applicationVariants.all { variant ->
    
        // Assigns a different version code for each output APK
        // other than the universal APK.
        variant.outputs.each { output ->
    
            // Stores the value of ext.abiCodes that is associated with the ABI for this variant.
            def baseAbiVersionCode =
                    // Determines the ABI for this variant and returns the mapped value.
                    project.ext.abiCodes.get(output.getFilter(OutputFile.ABI))
    
            // Because abiCodes.get() returns null for ABIs that are not mapped by ext.abiCodes,
            // the following code does not override the version code for universal APKs.
            // However, because we want universal APKs to have the lowest version code,
            // this outcome is desirable.
            if (baseAbiVersionCode != null) {
    
                // Assigns the new version code to versionCodeOverride, which changes the version code
                // for only the output APK, not for the variant itself. Skipping this step simply
                // causes Gradle to use the value of variant.versionCode for the APK.
                output.versionCodeOverride =
                        baseAbiVersionCode * 10 + variant.versionCode
            }
        }
        variant.outputs.all {
            outputFileName = "Lets-Vpn-${variant.versionName}-${variant.versionCode}.apk"
        }
    }
    

    相关文章

      网友评论

          本文标题:Android 打包

          本文链接:https://www.haomeiwen.com/subject/tlygtctx.html