Android Studio 1.0 and error "Library projects cannot set applicationId"
Asked Answered
I

6

119

After updating Android Studio to 1.0, I see this error:

Error: Library projects cannot set applicationId. applicationId is set to 'com.super.app' in default config.

I updated the Gradle plugin as suggested but I did not understand how to fix this.

Irrigate answered 9/12, 2014 at 9:2 Comment(0)
H
225

Based on this info:

ApplicationId in Library Projects

You cannot use applicationId to customize the package of a library project. The package name has to be fixed in library projects (and specified as packageName in the manifest). The Gradle plugin did not enforce this restriction earlier.

Removing applicationId variable from the library's build.gradle file should resolve the issue.

Holle answered 9/12, 2014 at 9:10 Comment(2)
Thanks, you drive me to the right direction. I added an answer that explains the "flavour" problem I have.Drudge
@Joel: i converted the module into a library, but i am not able to find the ApplicationId to remove. ApplicationId is not dr in build.gradle file. can you tell me where i can find in Android studio 1.0.1Caldeira
I
73

Thanks to Joel for his correct answer: I need to remove only 1 line from te .gradle file:

defaultConfig {
        applicationId "com.super.app"   <---- remove this line
        minSdkVersion 15
        targetSdkVersion 19
        versionCode 1
        versionName "1.0"
    }

becomes

defaultConfig {
        minSdkVersion 15
        targetSdkVersion 19
        versionCode 1
        versionName "1.0"
    }

and my AndroidManifest.xml

 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        package="com.super.app">
...

This is the right solution if you don't need to rename the package name of your app. To rename it you need to use "flavours":

android {
   ...
   productFlavors {
       flavor1 {
           applicationId 'com.super.superapp'
       }
   }
Irrigate answered 9/12, 2014 at 9:58 Comment(3)
Too bad two answers can't be checked as you included an example that Joel should have.Unvoiced
If I remove applicationID line, Can I publish in it Play store?(I mean update) Because there will be no application id for google play.Junkojunkyard
@gurkanstack if you remove the line in Gradle file, the name space defined in AndroidManifest.xml "package" will be used for pubblication.Drudge
R
4

Libraries can't set applicationId and if you are working in a multi-module project and picking up flavors from a separate file , none of the above answers will work. For a modularized app, you need the following steps -

Create a flavors.gradle file in project root directory

 ext.flavorConfig = { // 1
    
        flavorDimensions "pricing"
        productFlavors {
            free {
                dimension "pricing"
                ext.myApplicationIdSuffix = '.free' // 2
            }
            paid {
                dimension "pricing"
                ext.myApplicationIdSuffix = '.paid'
            }
        }
    
        productFlavors.all { flavor -> // 3
            if (flavor.hasProperty('myApplicationIdSuffix') && isApplicationProject()) {
                flavor.applicationIdSuffix = flavor.myApplicationIdSuffix
            }
        }
    
    }
    
    def isApplicationProject() { // 4
        return project.android.class.simpleName.startsWith('BaseAppModuleExtension')
     
    }
  • In 1 we export a closure so that we can use it in our modules’ build.gradle files.
  • In 2 we define a custom myApplicationIdSuffix property. We cannot simply have applicationIdSuffix as it is not possible to use it in library modules (build would fail if you did).
  • In 3 we iterate over created flavors and set applicationIdSuffix if we detect that it’s an application module only.
  • 4 is a way to check where this closure is being used.

All that’s left is to use this closure in our modules’ build.gradle files. E.g. in application module this would look like this:

apply plugin: 'com.android.application'
apply from: "${rootProject.projectDir}/flavors.gradle"

android {
    // other config...

    with flavorConfig
}

If this isn't clear, you can check out this article for better understanding.

Rebuild answered 23/7, 2021 at 13:7 Comment(0)
K
1

Just incase it helps some one :

When i imported an eclipse project into android studio,i got an error ::

"Error:Application and test application id cannot be the same"

Strange though,but i looked into the build.gradle and found the two placeholders,one for the application and other for testapplication.

I removed the testApplicationId from that as is suggested in this post and this helped me resolve the issue.

Note: This explaination is not related to the errors posted in this question,but might help someone who is getting a similar error.

Knipe answered 17/5, 2016 at 9:7 Comment(0)
P
1

You cannot define applicationId for your lib. But incase you want to use an identifier in your build file, which will give you, your library package name, you can define a variable for the module and then use the value as required.

eg : Library's build.gradle

apply plugin: 'com.android.library'

def libraryGroupId = 'com.google.example'
def libraryArtifactId = project.getName()
def libraryVersion = '1.1'

Also, you can use the value below as needed in your build file itself in lib.

android {
compileSdkVersion 28

defaultConfig {
    minSdkVersion 21
    targetSdkVersion 28
    versionCode 1
    versionName "$libraryVersion"
    resValue "string", "Library", libraryGroupId"
 }
}
Pinette answered 21/8, 2019 at 13:11 Comment(0)
C
0

If you are making a modular application, the applicationId variable should be in the build.gradle file of the main module, but the applicationId should not be in the build.gradle file of the other module or modules.

For example :

Main Module build.gradle

applicationId "com.example.exampleProject"

Other Module / Modules build.gradle

group = 'com.example.exampleOtherModule'
Chainey answered 29/5, 2023 at 10:58 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.