Using Android Studio how do I get a signed, non-debug and zip aligned APK?

 mobiledu2502887381 发布于 2023-02-07 10:16

Using Android Studio how do I get a signed, non-debug and zip aligned APK?

So far I can get a signed one but it gets rejected because it has debugging in it.

I can get a non debug release apk but it gets rejected because it's not zip aligned.

I can zip align it but then I can't upload it because that one is not signed.

Edit: I should mention that I'm on windows. Most everything I've looked at is linux based and difficult to separate linux paths from config paths.

Edit2: Things are on hold at the moment. I updated Android Studio and that killed everything because it comes with gradle 1.9 dependancies but doesn't install gradle 1.9 properly. So I thought I'd download the full installer with gradle 1.9 but the download link gives me the version I started with. I know. I should have known better than to update but given the issues I thought it might actually contain a fix.

Edit3: Problem solved. I have a full answer typed up ready to post but SO won't let me post it until tomorrow.

Scott Barta.. 16

All builds are signed, even debug ones (which are signed with a debug key). It's just a matter of setting it up to sign your release builds with the correct key. You can set up a signing config via the Project Structure dialog, or you can edit the build.gradle file by hand, following the instructions in the Gradle Plugin User Guide

Once your build file is set up, you can either generate the release APK from the command line with the command

./gradlew assembleRelease

on Linux or Mac, or on Windows:

gradlew.bat assembleRelease

or in the GUI, you can generate the release build by choosing it from the Build Variants view:

IDE window showing Build Variants view

building the APK, and signing it using the wizard.


m12lrpv.. 5

我已经解决了问题第1部分:k3v1n4ud3的链接确实有助于合并信息.谢谢你.这是我在项目文件夹下的整个build.gradle:

    buildscript {
        repositories {
            mavenCentral()
        }
        dependencies {
            classpath 'com.android.tools.build:gradle:0.6.+'
        }
    }
    apply plugin: 'android'

    repositories {
        mavenCentral()
    }

    android {
        compileSdkVersion 19
        buildToolsVersion "19.0.0"

        signingConfigs {
            debug {
                storeFile file("debug.keystore")
            }

            release {
                storeFile file("D:\\AndroidStudioProjects\\KeyStore\\Keystore_password1.jks")
                storePassword "password"
                keyAlias "MyAppName"
                keyPassword "password"
            }
        }

        productFlavors {
            free {
                packageName "com.mypackage.myappname"
            }

            paid {
                packageName "com.mypackage.myappname"
            }
        }

        buildTypes {
            debug {
                signingConfig signingConfigs.release
            }

            release {
                signingConfig signingConfigs.release
                debuggable false
                zipAlign true
            }

            /*
            alpha {
                packageNameSuffix ".alpha"
            }
            beta {
                packageNameSuffix ".beta"
            }*/
        }


        defaultConfig {
            minSdkVersion 7
            targetSdkVersion 19
        }
    }

    android.applicationVariants.all { variant ->
        if (variant.buildType.name == "release") {
            switch (variant.name) {
                case "FreeRelease":
                    variant.mergeResources.doFirst {
                        android.sourceSets.debug.setRoot("src/free")
                    }
                    break;
                case "PaidDebug":
                    variant.mergeResources.doFirst {
                        android.sourceSets.debug.setRoot("src/paid")
                    }
                    break;
            }
        }
        else if (variant.buildType.name == "debug") {
            switch (variant.name) {
                case "FreeDebug":
                    variant.mergeResources.doFirst {
                        android.sourceSets.debug.setRoot("src/debug/free")
                    }
                    break;
                case "PaidDebug":
                    variant.mergeResources.doFirst {
                        android.sourceSets.debug.setRoot("src/debug/paid")
                    }
                    break;
            }
        }
    }


    dependencies {
        compile 'com.android.support:appcompat-v7:+'
    }

第2部分:我使用了最初使用Build-> Generate Signed APK ...向导时创建的密钥库.注意使用的keyalias.经过半天的撞击我的头撞墙,我忘记了我输入的内容:-)

第3部分:这个线程帮助我设置源文件夹并理解风格.gradle构建变体的文件夹命名约定

第4部分:只有一个AndroidManifest.xml,我无法在包名上使用后缀.使用后缀时,上传到设备时会被拒绝.当build.gradle的每个例子都包含后缀时,这就成了一个问题.

第5部分:使用View-> Tool Windows-> BuildVariants来调出构建变体.第二列实际上是一个下拉列表.选择你想要在这里构建的内容,否则它将继续构建调试版本.(为什么它不在构建菜单下或运行/调试配置是一个谜?)

第6部分:未来......我必须尝试解决这些问题以及如何设置它们,因为我最终希望在相同的代码库中部署免费和付费版本.我将开始使用自己的密钥签署调试版本.

2 个回答
  • 我已经解决了问题第1部分:k3v1n4ud3的链接确实有助于合并信息.谢谢你.这是我在项目文件夹下的整个build.gradle:

        buildscript {
            repositories {
                mavenCentral()
            }
            dependencies {
                classpath 'com.android.tools.build:gradle:0.6.+'
            }
        }
        apply plugin: 'android'
    
        repositories {
            mavenCentral()
        }
    
        android {
            compileSdkVersion 19
            buildToolsVersion "19.0.0"
    
            signingConfigs {
                debug {
                    storeFile file("debug.keystore")
                }
    
                release {
                    storeFile file("D:\\AndroidStudioProjects\\KeyStore\\Keystore_password1.jks")
                    storePassword "password"
                    keyAlias "MyAppName"
                    keyPassword "password"
                }
            }
    
            productFlavors {
                free {
                    packageName "com.mypackage.myappname"
                }
    
                paid {
                    packageName "com.mypackage.myappname"
                }
            }
    
            buildTypes {
                debug {
                    signingConfig signingConfigs.release
                }
    
                release {
                    signingConfig signingConfigs.release
                    debuggable false
                    zipAlign true
                }
    
                /*
                alpha {
                    packageNameSuffix ".alpha"
                }
                beta {
                    packageNameSuffix ".beta"
                }*/
            }
    
    
            defaultConfig {
                minSdkVersion 7
                targetSdkVersion 19
            }
        }
    
        android.applicationVariants.all { variant ->
            if (variant.buildType.name == "release") {
                switch (variant.name) {
                    case "FreeRelease":
                        variant.mergeResources.doFirst {
                            android.sourceSets.debug.setRoot("src/free")
                        }
                        break;
                    case "PaidDebug":
                        variant.mergeResources.doFirst {
                            android.sourceSets.debug.setRoot("src/paid")
                        }
                        break;
                }
            }
            else if (variant.buildType.name == "debug") {
                switch (variant.name) {
                    case "FreeDebug":
                        variant.mergeResources.doFirst {
                            android.sourceSets.debug.setRoot("src/debug/free")
                        }
                        break;
                    case "PaidDebug":
                        variant.mergeResources.doFirst {
                            android.sourceSets.debug.setRoot("src/debug/paid")
                        }
                        break;
                }
            }
        }
    
    
        dependencies {
            compile 'com.android.support:appcompat-v7:+'
        }
    

    第2部分:我使用了最初使用Build-> Generate Signed APK ...向导时创建的密钥库.注意使用的keyalias.经过半天的撞击我的头撞墙,我忘记了我输入的内容:-)

    第3部分:这个线程帮助我设置源文件夹并理解风格.gradle构建变体的文件夹命名约定

    第4部分:只有一个AndroidManifest.xml,我无法在包名上使用后缀.使用后缀时,上传到设备时会被拒绝.当build.gradle的每个例子都包含后缀时,这就成了一个问题.

    第5部分:使用View-> Tool Windows-> BuildVariants来调出构建变体.第二列实际上是一个下拉列表.选择你想要在这里构建的内容,否则它将继续构建调试版本.(为什么它不在构建菜单下或运行/调试配置是一个谜?)

    第6部分:未来......我必须尝试解决这些问题以及如何设置它们,因为我最终希望在相同的代码库中部署免费和付费版本.我将开始使用自己的密钥签署调试版本.

    2023-02-07 10:18 回答
  • All builds are signed, even debug ones (which are signed with a debug key). It's just a matter of setting it up to sign your release builds with the correct key. You can set up a signing config via the Project Structure dialog, or you can edit the build.gradle file by hand, following the instructions in the Gradle Plugin User Guide

    Once your build file is set up, you can either generate the release APK from the command line with the command

    ./gradlew assembleRelease
    

    on Linux or Mac, or on Windows:

    gradlew.bat assembleRelease
    

    or in the GUI, you can generate the release build by choosing it from the Build Variants view:

    IDE window showing Build Variants view

    building the APK, and signing it using the wizard.

    2023-02-07 10:18 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有