Android Studio 1.0 and error “Library projects cannot set applicationId”

后端 未结 4 846
北恋
北恋 2020-12-07 19:46

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

Error: Library projects cannot set applicationId. applicationId is set to \'com

相关标签:
4条回答
  • 2020-12-07 20:23

    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.

    0 讨论(0)
  • 2020-12-07 20:23

    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"
     }
    }
    
    0 讨论(0)
  • 2020-12-07 20:25

    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.

    0 讨论(0)
  • 2020-12-07 20:28

    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'
           }
       }
    
    0 讨论(0)
提交回复
热议问题