Android is library error

Android Studio library «error: package does not exist»

I have created Android library as Android Studio module. Added as dependency to my root module. While coding I can import any class from library package but while I’m trying run the application I’m getting an error package some.mylibrary.project does not exist .

build.gradle root module

build.gradle library module

settings.gradle

P.S. I have to mention that the project was exported from Eclipse IDE so the project structure is different from default one.

6 Answers 6

For Android Studio 2.2.2

Yes, in library module, it can’t use the apply plugin: com.android.application statement in the module definition, yes, use apply plugin: com.android.library instead. (still in lib module)

But then you have to do the following:

  1. Expose the same SDK versions in Gradle files for both modules.
  2. Right click on your projects «app» module folder and click on -> open module settings
  3. Click on the «dependencies» tab
  4. Click on the + sign to add a new dependency and select «Module Dependency»
  5. Look for the library you need and add it.

Also while naming your lib module avoid capitals.

If you have a library module, it can’t use the apply plugin: ‘com.android.application’ statement in the module definition, or the build will silently fail as you’re seeing. use apply plugin: ‘com.android.library’ instead.

A bug has been filed to request that the build system fail loudly instead of silently when this happens: https://code.google.com/p/android/issues/detail?id=76725

The answer above is somewhat lacking If you project java add in Kotlin getting get this error

  • Tools Tab Kotlin and Configure Kotlin
  • (Select Android with Gradle) after select with Modules

Project build.gradle add

Apps build.gradle

Kotlin

In build-gradle app, add this row:

This error happens when you change the package name and try to run the code. this occurs because the android studio still has the cache of your package with an old name.

Also, cross-check all the imports as well as an imported package in your code so that no different package name exists. For example, is common this error is referring to another imported file near where the error is occurring. Check previous imports near.

To fix this error you can try to do an ‘invalidate caches / Restart’ option from the File menu in android studio. Choose “Invalidate and restart option” and close Android Studio.

Another reason for this error, is when one changes the project’s path root folder or in any of the modules it depends. In this particular case, to fix this error you need to remove the affected modules, and re-add them again. Next don’t forget to do an ‘invalidate caches / Restart’ option from the File menu in android studio. Choose “Invalidate and restart option” and close Android Studio.

Clean your project from android studio :

  • “Build -> Clean Project”. This will clear your build folders.
  • Remove your .gradle directory from the root of your project. It contains some Gradle cache files.
  • Delete also the .idea directory (make a backup before). It contains some project configuration files.

Restart Android Studio.

Finally

if the error still persists, you need to move the affected files to an external directory of the project’s root folder. And on Android Studio, create manually each filename as previous, and copy the code inside from the old file. This will defiantly solve this error.

Источник

Error building Android library: Direct local .aar file dependencies are not supported

We recently upgraded to Android Gradle Plugin 4.0.0-beta03. We are now seeing this error when building one of our library modules

Читайте также:  Java ide running on android

I can see this was added to AGP a few months ago. But they provide no further info on why.

  1. What was the problem? Any more info? I can’t find a single bug report anywhere.
  2. How exactly can I fix this? Is this saying that I can’t build one .aar that depends on other local .aars? What if this local aar was instead hosted on Maven Central or another remote repo? Why would that make a difference?

16 Answers 16

I recently encountered the same issue, the fix was to remove the library from libs/ and import it using File -> New -> New Module -> Import .JAR/.AAR Package , then referencing it in the library module build.gradle file:

If you are on a newer Android Studio version (4.0.0+), this option is not available. Instead you have to do it manually.

  1. Create a new directory and put the following content into the build.gradle file withing the new directory:
  1. Place the aar into this new directoy. Next to the build.gradle file.
  2. Add the new created Gradle project to the settings.gradle file:
  1. Include the project in your library where you want to use the aar :

When building an Android library that depends on other Android libraries (i.e., aar files), you will get the following error message if you include the aar files as dependencies in the project:

Direct local .aar file dependencies are not supported when building an AAR. The resulting AAR would be broken because the classes and Android resources from any local .aar file dependencies would not be packaged in the resulting AAR. Previous versions of the Android Gradle Plugin produce broken AARs in this case too (despite not throwing this error).

As the above message states, when you build an Android library project, any aar it depends on is not packaged. If you built this way prior to AGP (Android Gradle Plugin) 4, you probably noticed that you had to include the aar dependencies on the project consuming your library.

You can compile your Android library project by specifying that the aar dependencies are compileOnly . See this for more info on when to use compileOnly .

So just add the following to your app build.gradle file:

Note that if you do this you will have to include the aar dependencies on the application project that consumes your library.

Alternatively, you can create a module that imports your aar dependency as @Sandi mentioned in the answer above.

Another way is to publish your aar dependencies to a maven repository and then add them to your library project like this:

Источник

Android Studio: Plugin with id ‘android-library’ not found

I’ve been trying to get ActionBarSherlock to work and having some issue. One issue I’ve come across is the following message when trying to build it:

I’m treating this as an ABS issue in a seperate thread, so here I’m curious how to address the general issue of:

Here is the build.gradle:

10 Answers 10

Instruct Gradle to download Android plugin from Maven Central repository.

You do it by pasting the following code at the beginning of the Gradle build file:

Replace version string 1.0.+ with the latest version. Released versions of Gradle plugin can be found in official Maven Repository or on MVNRepository artifact search.

Just for the record (took me quite a while) before Grzegorzs answer worked for me I had to install «android support repository» through the SDK Manager!

Install it and add the following code above apply plugin: ‘android-library’ in the build.gradle of actionbarsherlock folder!

In later versions, the plugin has changed name to:

And as already mentioned by some of the other answers, you need the gradle tools in order to use it. Using 3.0.1, you have to use the google repo, not mavenCentral or jcenter:

Use mavenCentral() adding in the build.gradle file the script:

For me, on android studio 4.2 C15 SDK30, this is what worked:

Читайте также:  Create apk from android app

Add the below to the build.gradle project module:

// Top-level build file where you can add configuration options common to all sub-projects/modules.

In addition to previous answers, when using Gradle Kotlin DSL, you should add resolution strategy for Android plugins in your settings.gradle.kts :

Then, you need to specify plugin version in your build.gradle.kts , e.g.:

No buildscript is required.

Believe it or not, an empty settings.gradle file in the com.android.library module’s root directory brought this error back from the grave in Android Studio 4.2.2.

Deleting the empty settings.gradle file fixed it.

This error is very simple , it means that when you are adding dependency of dagger hilt, you forget to add classpath of dagger hilt 😂🤣. So simply go to your build.gradle(project) and add this classpath

And boom error is gone 😍❤

Note :- whatever dependency you are adding if it has plugin , make sure don’t forget to add classpath of that dependency😊

Not the answer you’re looking for? Browse other questions tagged gradle android-studio android-build build.gradle gradlew or ask your own question.

Linked

Hot Network Questions

Subscribe to RSS

To subscribe to this RSS feed, copy and paste this URL into your RSS reader.

site design / logo © 2021 Stack Exchange Inc; user contributions licensed under cc by-sa. rev 2021.12.3.40888

By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy.

Источник

Android Studio 1.0 and error «Library projects cannot set applicationId»

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.

5 Answers 5

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.

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

and my AndroidManifest.xml

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»:

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.

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

  • 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:

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

Источник

Android design support library for API 28 (P) not working

I’ve configured android-P SDK environment successfully. When I attempt to use the android design support library I face project build errors. Project configurations are:

Читайте также:  Pokemon omega ruby для андроид

IDE: 3.2 Canary 17 Target API: 28 Compile API: 28

And build failed error is:

Manifest merger failed : Attribute application@appComponentFactory value=(androidx.core.app.CoreComponentFactory) from [androidx.core:core:1.0.0-alpha3] AndroidManifest.xml:22:18-86 is also present at [com.android.support:support-compat:28.0.0-alpha3] AndroidManifest.xml:22:18-91 value=(android.support.v4.app.CoreComponentFactory). Suggestion: add ‘tools:replace=»android:appComponentFactory»‘ to element at AndroidManifest.xml:6:5-40:19 to override.

18 Answers 18

You can either use the previous API packages version of artifacts or the new Androidx, never both.

If you wanna use the previous version, replace your dependencies with

if you want to use Androidx:

Important Update

Android will not update support libraries after 28.0.0 .

This will be the last feature release under the android.support packaging, and developers are encouraged to migrate to AndroidX 1.0.0.

  • Don’t use bothSupport and AndroidX in project.
  • Your library module or dependencies can still have support libraries.Androidx Jetifier will handle it.
  • Use stable version of androidx or any library, because alpha, beta, rc can have bugs which you dont want to ship with your app.

to your manifest application

I’ve used that option:

With Android Studio 3.2 and higher, you can quickly migrate an existing project to use AndroidX by selecting Refactor > Migrate to AndroidX from the menu bar.

Google has introduced new AndroidX dependencies. You need to migrate to AndroidX, it’s simple.

I replaced all dependencies to AndroidX dependencies

New AndroidX design dependency

Automatic AndroidX migration option (supported on android studio 3.3+)

Migrate an existing project to use AndroidX by selecting Refactor > Migrate to AndroidX from the menu bar.

1.Added these codes to your app/build.gradle:

2.Modified sdk and tools version to 28:

2.In your AndroidManifest.xml file, you should add two line:

Design support library for androidX is implementation ‘com.google.android.material:material:1.0.0’

First of all, you should look gradle.properties and these values have to be true. If you cannot see them you have to write.

After that you can use AndroidX dependencies in your build.gradle (Module: app). Also, you have to check compileSDKVersion and targetVersion. They should be minimum 28. For example I am using 29.

So, an androidx dependency example:

However be careful because everything is not start with androidx like cardview dependency. For example, old design dependency is:

So, you have to search and read carefully.

open file gradle.properties and add these two lines to it:

clean and build

I cross that situation by replacing all androidx.* to appropiate package name .

change your line

  • remove tools:replace=»android:appComponentFactory» from AndroidManifest

Note: You should not use the com.android.support and com.google.android.material dependencies in your app at the same time.

Add Material Components for Android in your build.gradle(app) file

If your app currently depends on the original Design Support Library, you can make use of the Refactor to AndroidX… option provided by Android Studio. Doing so will update your app’s dependencies and code to use the newly packaged androidx and com.google.android.material libraries.

If you don’t want to switch over to the new androidx and com.google.android.material packages yet, you can use Material Components via the com.android.support:design:28.0.0-alpha3 dependency.

Below code worked perfectly with me:

Android documentation is clear on this.Go to the below page.Underneath,there are two columns with names «OLD BUILD ARTIFACT» and «AndroidX build artifact»

Now you have many dependencies in gradle.Just match those with Androidx build artifacts and replace them in the gradle.

That won’t be enough.

Go to your MainActivity (repeat this for all activities) and remove the word AppCompact Activity in the statement «public class MainActivity extends AppCompatActivity » and write the same word again.But this time androidx library gets imported.Until now appcompact support file got imported and used (also, remove that appcompact import statement).

Also,go to your layout file. Suppose you have a constraint layout,then you can notice that the first line constraint layout in xml file have something related to appcompact.So just delete it and write Constraint layout again.But now androidx related constraint layout gets added.

repeat this for as many activities and as many xml layout files..

But don’t worry: Android Studio displays all such possible errors while compiling.

Источник

Оцените статью