android studio - Why does Gradle disregard release{} and implement a rule on debug build as well? -


i not sure if happened before, think happened after recent updates of android studio , gradle.

namely, trying set output path of release apk. made code this

buildtypes {     release {         minifyenabled false         proguardfiles getdefaultproguardfile('proguard-android.txt'), 'proguard-rules.pro'          signingconfig signingconfigs.config          def outputpathname = "./apk-release.apk"         applicationvariants.all { variant ->             variant.outputs.each { output ->                 output.outputfile = file(outputpathname)             }         }     } } 

this move apk default location (/build/outputs/apk) , place next build.gradle file.

however, release{} being disregarded , android studio moves debug build location renaming it. either create signed apk or press debug icon test debug release, apk being moved , renamed. , should stay inside default location, right?

why happening? bug inside android studio gradle or bug in code?

note: noticed same happens in other project in create custom name apk. rename debug apk , in same manner disregard release{}.

android studio version: 1.3. preview 5

the release{} being disregarded

not really. every line of code in build.gradle executed when script processed.

gradle scripts not there execute code @ build time. there define object model of build process. in android studio, gradle scripts not read in , interpreted @ build time; read in when project opens or when "sync project gradle files". object model populates things build variants view.

the release closure not saying "this stuff should done on release build". merely says "hey, can't recognize, minifyenabled, see if that's property or method or on here release object". write beginning portion of release closure this:

buildtypes {     release.minifyenabled false     release.proguardfiles getdefaultproguardfile('proguard-android.txt'), 'proguard-rules.pro'     release.signingconfig signingconfigs.config } 

or even:

   buildtypes.release.minifyenabled false    buildtypes.release.proguardfiles getdefaultproguardfile('proguard-android.txt'), 'proguard-rules.pro'    buildtypes.release.signingconfig signingconfigs.config 

if wanted.

that's why see sort of applicationvariants loop @ end of android {}, (i think) applicationvariants part of gradle android plugin dsl, , iterate on application variants.

so, if want affect release build, in loop, check variant build type:

    def outputpathname = "./apk-release.apk"     applicationvariants.all { variant ->         def name = variant.buildtype.name          if (name.equals(com.android.builder.core.builderconstants.debug)) {             return; // skip debug builds.         }          variant.outputs.each { output ->             output.outputfile = file(outputpathname)         }     } 

(there's slicker way of filtering this, i've been using...)


Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -