I have moved from Ant script to gradle build script. But I don't know any way to get package name or applicationId in gradle build script.
You can find an app's package name in the URL of your app's Google Play Store listing. For example, the URL of an app page is play.google.com/store/apps/details? id=com. example.
Every Android app has a unique application ID that looks like a Java or Kotlin package name, such as com. example. myapp. This ID uniquely identifies your app on the device and in the Google Play Store.
The applicationId exactly matches the Java-style package name you chose during project setup in android studio. However, the application ID and package name are independent of each other beyond this point.
All Android apps have a package name. The package name uniquely identifies the app on the device; it is also unique in the Google Play store.
project.afterEvaluate {
project.android.applicationVariants.all { variant ->
def applicationId = [variant.mergedFlavor.applicationId, variant.buildType.applicationIdSuffix].findAll().join()
...
}
}
or define one in foo.gradle :
// foo.gradle
def appId = 'com.example.bar'
ext.appId = appId
// build.gradle
apply from: './foo.gradle'
...
defaultConfig {
...
applicationId appId
}
// other.gradle you want
apply from: './foo.gradle'
...
task example {
println(appId)
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With