Question

I am trying to run a project that is android-library plugin in Gradle and I get this error in run configurations: "The module cannot be Android library". The project is running as regular Android plugin. Is there any way to run android library in Android studio?

Était-ce utile?

La solution

You cannot run an Android library project using any tool. An Android library project is a library, not an app. You cannot generate an APK from an Android library project. Instead, you attach an Android library project to another app.

You can read more about library projects in the developer documentation.

Autres conseils

If you want to check whether the implementation of the android library project is correct, we have to compile it and check.As above mentioned, we can't run android library projects. So we have to find a way to compile the library module.For that we can add the newly implemented library module to a non library module as follows.

"my module Hierarchy"

In here "mylibrary" is the library module which I'm going to use in the "app" module.In my library module there are aidl files. so to work the app finely the aidl files also should compile.We can add dependency for app module as follows,

go to File->Project Sturcture->app->Dependencies-> + ->mylibrary->ok

How to add Library to the project

Now we can run the app by just clicking "Sync project with gradle files"(In tool bar 21st icon from the left-icon with an arrow and a circle ) button.

Run gradle files

Thats all :)

    //apply plugin: 'com.android.library'
    apply plugin: 'com.android.application'

android{


    defaultConfig {
      applicationId "com.testbook.tbapp"
    }

}

Now you can run the library as an app

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top