Android Studio: Is creating a signature configuration necessary when creating a custom assembly type?

I have created custom type buildTypes as shown below and I am not using default debug and release buildTypes

buildTypes { releasefree { minifyEnabled true shrinkResources true proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } releasepro { minifyEnabled true shrinkResources true proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' applicationIdSuffix ".pro" } debugfree { shrinkResources true applicationIdSuffix ".debug" debuggable true } debugpro { shrinkResources true applicationIdSuffix ".pro.debug" debuggable true } } 

The reason for this: I have several productFlavors and you need to have a PRO version for each, and I felt that it was easier than creating a separate PRO flavor for each free one. My code handles the difference using the APPLICATION_ID from the BuildConfig class. Another reason is that I have customized classes, and I will need to repeat it twice if I have two different tastes. I know that I can customize the source, but I had problems with this when I had too many tastes. Very difficult to track.

Now the problem is:. When I try to run the application using the buildType custom build option, it asks me to create a signature configuration for each custom build type.

This is the error message that I see

Similarly, I see a message in the Run console on execution:

Failure [INSTALL_PARSE_FAILED_NO_CERTIFICATES]

Installation error because the APK was either not signed or signed incorrectly. If this is a Gradle-based project, then make sure that the signing configuration is specified in the Gradle build script.

I understand that this may be required. But, what I was trying to figure out was: Is there a tuning method that I could change so that the debugfree and debugpro buildTypes created can bypass the requirements for setting up the signature just like default debug buildType? I know that creating a signature configuration is one minute, and I will do it if I don't get something soon. But just out of curiosity, I want to understand what needs to be done to make the custom buildType type work by default, and does not require a signature setting.

Tried setting

 debuggable true 

(which was the only difference in the properties of debug buildType by default and my custom debug buildType type), hoping it would work the same way as debug buildType by default, but that didn't happen. What else needs to be changed so that the custom type buildType works as by default, that is, it does not require signature settings.

+1
source share
2 answers

Build types do not have strict inheritance. However, you can use what constitutes the copy constructor:

 debugfree.initWith(buildTypes.debug) 

where debugfree is the type of assembly you want to define, and debug is the type of assembly you want to copy from.

Do this before the rest of the initialization of the new type of assembly (otherwise initFrom() can destroy parts of this initialization).

In particular, since debug has an already configured signature configuration, starting a new build type by initializing from debug uses the same debug signature configuration.

However, be very careful when using the debug assembly type as a starting point. You do not want to accidentally terminate an attempt to send applications with this debug signature configuration.

+2
source

Based on @CommonsWare's comment on my question above, I modified buildTypes as follows, and it worked like a charm. You must initialize the custom buildType type with the default buildType before adding a custom configuration. This was for debugging as well as for issuing special types, and it did the trick.

Spending it here again, in case some curious soul like me can benefit from it.

 buildTypes { releasefree.initWith(buildTypes.release) releasefree { minifyEnabled true shrinkResources true proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } releasepro.initWith(buildTypes.release) releasepro { minifyEnabled true shrinkResources true proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' applicationIdSuffix ".pro" } debugfree.initWith(buildTypes.debug) debugfree { shrinkResources true applicationIdSuffix ".debug" debuggable true } debugpro.initWith(buildTypes.debug) debugpro { shrinkResources true applicationIdSuffix ".pro.debug" debuggable true } } 
+1
source

All Articles