Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set up signingConfigs only for release variants?

I've set up continuous deployment with fastlane that handles my code signing for release apps, annoying bit is that when I run them in debug in on my machine android studio fails because it can't find path to them (they are declared as env variables demonstrated below). I can fix this by creating dummy data for the env variables, but would rather android studio ignore this bit of code unless it is running a release buid.

So in my app/build.gradle right after defaultConfig I have

signingConfigs {
    release {
        storeFile file(System.getenv("MYAPP_STOREFILE"))
        storePassword System.getenv("MYAPP_STORE_PASSWORD")
        keyAlias System.getenv("MYAPP_KEY_ALIAS")
        keyPassword System.getenv("MYAPP_KEY_PASSWORD")
    }
}

I thought that putting it under release would do the trick, but no luck :/

like image 548
Ilja Avatar asked Dec 19 '25 07:12

Ilja


1 Answers

Not a super elegant solution, but just wrap it with try-catch?

signingConfigs {
    release {
        try {
            storeFile file(System.getenv("MYAPP_STOREFILE"))
            storePassword System.getenv("MYAPP_STORE_PASSWORD")
            keyAlias System.getenv("MYAPP_KEY_ALIAS")
            keyPassword System.getenv("MYAPP_KEY_PASSWORD")
       } catch (Exception ignored) {
            // Do stuff or just ignore
       }
    }
}

If you don't want try-catch you can try the following:

signingConfigs {
    release {
        storeFile System.getenv("MYAPP_STOREFILE") ? file(System.getenv("MYAPP_STOREFILE")) : null
        storePassword System.getenv("MYAPP_STORE_PASSWORD")
        keyAlias System.getenv("MYAPP_KEY_ALIAS")
        keyPassword System.getenv("MYAPP_KEY_PASSWORD")
    }
}
like image 122
dipdipdip Avatar answered Dec 21 '25 21:12

dipdipdip



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!