Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I sign testing apk in Android Studio?

I am developing an app in such an android device that requires each app to be signed with a specific key, even the testing apk.

I know how to sign an app by configuring build.gradle. But signing testing app (Instrumentation test) seems no such configing, am I missing something ?

like image 204
CompileLife Avatar asked Dec 13 '16 02:12

CompileLife


2 Answers

Thanks for NateZh and TWL.

Yes, the answer is to add flowing lines to build.gradle:

signingConfigs {
    debug {
        keyPassword 'your pw'
        storeFile file('your keystore file path')
        storePassword 'your pw'
        keyAlias 'your alias'
    }
}

But, there are more to be take care of:

  1. When using signingConfigs.debug, this tells gradle it's debug key, no need to specific buildTypes.debug.signingConfig again

  2. SigingConfigs.debug also take effect when building instrumentation test

  3. In multi-modules project, if you want to test a module, you should include signingConfigs.debug in the module's build.gradle.

For example, my project looks like:

app
    -build.gradle
libs
    -src/androidTest/java/com/my/MyTest.java
    -build.gradle

Adding signingConfigs.debug to app has no effect when I want to run libs' AndroidDebugTest. Instead, adding signingConfigs.debug to libs' build.gradle do the work.

Hope it's helpful to others.

like image 129
CompileLife Avatar answered Nov 11 '22 16:11

CompileLife


try this in build.gradle

signingConfigs {
    release {
        keyPassword 'your pw'
        storeFile file('your keystore file path')
        storePassword 'your pw'
        keyAlias 'your alias'
    }
}

buildTypes {
    release {
        signingConfig signingConfigs.release
    }

    debug {
        minifyEnabled false
        signingConfig signingConfigs.release
    }
}
like image 3
NateZh Avatar answered Nov 11 '22 18:11

NateZh