简体   繁体   中英

Android generate unsigned apk using gradle

I have an Android Project (with Android Studio and Gradle) and a Jenkins CI Server that build this one.

What I'm trying to do is to generate a completely unsigned certificate .

In fact, when the server builds the application, it does generate an -unsigned.apk but it seems that this apk is signed by the developper certificate .

In fact I checked this out by downloading the apk and running the following command (after reading How do I verify that an Android apk is signed with a release certificate? )

jarsigner -verify -verbose -certs app-unsigned.apk | grep Android

So the output is like

X.509, CN=Android Debug, O=Android, C=US

(with a lot of rows)

For what it worth, I build the app running the gradle tasks :

clean assemble lint

And after that, I zipaling all the apks by running

zipalign -f -v 4 *.apk

My build.gradle doesn't contain any signing option

android {
    compileSdkVersion 19
    buildToolsVersion '19.0.1'

    defaultConfig {
        minSdkVersion 10
        targetSdkVersion 19
    }

    buildTypes {
        debug {
            // proguard
            runProguard false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
            // ZipAlign
            zipAlign false
        }

        release {
            // proguard
            runProguard true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
            // ZipAlign
            zipAlign true
        }
    }

    productFlavors {
        defaultFlavor {
        proguardFile 'proguard-rules.txt'
        }
    }

    lintOptions {
        // Don't abort if Lint finds an error, otherwise the Jenkins build
        // will be marked as failed, and Jenkins won't analyse the Lint output
        abortOnError false
    }
}

What can I try next?

Ok I managed to get the result.

The fact was in the task I was using for my build.

I used

clean assemble lint

And then I changed for

clean assembleRelease lint

The generated apk is now app-release-unsigned.apk but when I run the command

jarsigner -verify -verbose -certs app-release-unsigned.apk | grep Android

the output is nothing so I guess it worked.

This is a mystery for me because I thought assemble was a kind of shortcut for assembleDebug and then assembleRelease like I read on gradle but it seems that the apk generated has the same name (app-release-unsigned.apk) but one of them is signed, the other not.

Anyway, using assembleRelease seems to work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM