Android Studio 1.0 and error “Library projects can

2019-01-16 10:50发布

问题:

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.

回答1:

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.



回答2:

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'
       }
   }


回答3:

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.



回答4:

I've tried deleting the applicationId line. However, it throws other error:

FAILURE: Build failed with an exception.

  • What went wrong: A problem occurred configuring project ':app'.

    Could not resolve all dependencies for configuration ':app:_debugApkCopy'. Could not find com.bst.material-dialogs:core:0.9.0.2. Required by: polar-dashboard-master:app:unspecified Could not find com.bst:drag-select-recyclerview:0.3.6. Required by: polar-dashboard-master:app:unspecified Could not find com.bst:bridge:3.2.5. Required by: polar-dashboard-master:app:unspecified Could not find com.bst:sectioned-recyclerview:0.2.3. Required by: polar-dashboard-master:app:unspecified Could not find com.bst:assent:0.2.5. Required by: polar-dashboard-master:app:unspecified Could not find com.bst:icon-request:1.5.2. Required by: polar-dashboard-master:app:unspecified Could not find com.bst:inquiry:3.2.1. Required by: polar-dashboard-master:app:unspecified

  • Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.