Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get package name or applicationId in gradle build script?

Tags:

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.

See image

See image

like image 436
Tuan Nguyen Avatar asked Jun 07 '17 01:06

Tuan Nguyen


People also ask

How do I find app package name?

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.

What is applicationId in build Gradle?

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.

Is package name and application ID same?

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.

What is application package name?

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.


1 Answers

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)
}
like image 62
2BAB Avatar answered Sep 30 '22 13:09

2BAB