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?
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.
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.
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
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.
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
Related
I want to convert existing android studio app project into an android library and add it as a dependency to new android studio app project.
android studio app project has three android library projects as dependencies along with firebase and Crashlytics integration,
Now i want to convert this entire project into one android library and add it to another android studio app project.
i have tried changing below lines
//from
apply plugin: 'com.android.application'
//to
apply plugin: 'com.android.library'
android library contains google-services.json, and other API keys. so when i add android library as a dependency to new app project, it is only taking modules from android library not google-services.json and other settings
How to solve this issue, Or there is a another process to convert app project to library
You can init Firebase with values in your google-service.json in your code side. So that you can get rid of google-service.json file.
I'm trying to create an Android library for two days already.
Realy need your help.
I have an existing App which I want to do as a Library.
According to Android developers documentation:
f you have an existing app module with all the code you want to reuse,
you can turn it into a library module as follows:
Open the module-level build.gradle file. Delete the line for the
applicationId. Only an Android app module can define this. At the top
of the file, you should see the following: apply plugin:
'com.android.application' Change it to the following: apply plugin:
'com.android.library'
I have done this step.
The next step is saying:
When you want to build the AAR file, select the library module in the
Project window and then click Build > Build APK.
I don't really understand how to build the AAR file.
Also in my library, I have others dependencies which I need to be in my Library.
I tried a lot of suggestions in StackOverflow but didn't find the answer.
Unfortunately, I didn't find a good example of creating an Android Library with dependencies.
I don't really understand how to build the AAR file
Just compile the library or use ./gradlew build.
The output will be stored under the library's subdirectory under build/outputs/aar.
I have others dependencies which I need to be in my Library.
The aar file doesn't contain the transitive dependencies.
I suggest you publishing your library into a public or private maven repository.
I'm trying to build an AR project in Unity and use it as a library in my native android app.
I used this article as a guideline:
https://medium.com/#davidbeloosesky/embedded-unity-within-android-app-7061f4f473a
I successfully imported the project to Android Studio, but the settings.gradle file is missing.
Although I can run the project from the studio, when I convert it to a library and use its aar file in my native android app - I fail to build the project.
Has anyone succeeded doing it?
I followed the guideline and it worked out. I put the .aar file below the native app libs file. In app build.gradle, under dependencies add:
implementation(name:"AndroidPluginDemo",ext:"aar")
and under android add
repositories {
flatDir {
dirs 'libs' //this way we can find the .aar file in libs folder
}
}
Just to add on to the above answers asking about the camera not working, the problem for me was the one of the classes in the unity app wasn't being found when i imported that library into my android app.
When you're converting the application to a library project, take note in the build.gradle of the dependencies.
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation(name: 'vlsdk', ext:'aar')
}
In my case I had to find the 'vlsdk.aar' file that was being referenced, and import that as a new module (as is done in step 6 of the tutorial) into my native android app. Hope this helps.
I know this is very old and i hope you have found a solution. but to anyone else facing this issue.
Add the ".aar" libraries found in the libs folder of unity's exported project to the build.gradle file as dependencies(they also need to be physically present in the native projects libs folder).
In my case when i built the .aar library from the exported project it did not add the dependencies(unity exported project also has dependencies found in the libs folder). I only excluded the "unity-classes.jar" file as my unity code is already in the ".aar" that i created.
Check the following link
https://medium.com/#randive.rishiraj/7-steps-to-integrate-google-arcore-unity-project-to-a-native-android-app-d85793ba0b37
Hope this helps.
To implement Unity features inside native apps we need to change Unity Project as a library, and then integrate inside our native application.
From version 2019.3.a2 Unity introduced a new feature Unity as a library in native apps both Android and Ios.
Steps:
1. Export Unity Project as an Library (Android)
2. Add Unity Library Module inside Native Android Project
3.Show Unity View inside Android Activity
Previously, the exported Unity project will have only one gradle module and one manifest file.
But now the Structure has been changed to two gradle modules.
1. launcher
2.unityLibrary
Both launcher and unityLibrary module will have its own build.gradle and manifest files.
unityLibrary - module will have Unity runtime and project data, it can be easily integrated into any other gradle project. It will help
to integrate Unity inside our native android project.
launcher - module will have all icons and the application name.
But we want use only unityLibrary module as an library inside our native android project.
This blog helps to implement unity view in your native android app.
https://navinkumar0118.medium.com/show-unity-view-inside-native-android-app-8035b9b6895a
I'm stuck trying to add https://github.com/ge0rg/MemorizingTrustManager to my Android Studio project (which consists of one MainActivity only at the moment). I tried the steps in the readme and did some Google research but no success. I just can't manage to integrate this package as library. Maybe someone has already succeeded doing so and can help me out.
Whenever I try to add this as library, its add only example module(example is the name of module in the library) but I want to add whole project in studio project.
EDIT
Project Screenshot
Download Demo Screenshot
It seems like you've put a folder of sources in the libs directory. It would be better to included those sources as their own module just as you have done with the emoji library.
Click an existing module
Press F4
Click the Green Plus add-module button in the top left.
Select Import Gradle Project
Select the MemorizingTrustManager sources directory
Double check that Android Studio has added dependencies for you, otherwise look in settings.gradle and add the module name (eg. include :memorizingTrustManager), then in your main module, add the same module to dependencies:
compile project(':memorizingTrustManager')
Finally check the gradle file of the imported MemorizingTrustManager module and ensure it has
apply plugin: 'com.android.library'
instead of
apply plugin: 'com.android.application'
and that it does not contain an applicationId
i'm migrating from Eclipse to Android Studio and i am facing this problem:
In Eclipse i have a Library project A (library) and a Application project B (launcher).
My launcher project, has a reference to my library project. My library project has all the logic with a lot of activities, resources etc... and a dummy AndroidManifest.xml file that it is an copy of my launcher manifest but with renamed packages to make it compatible. When i want to test the logic of my Library project in Eclipse, i simply unmark "library" checkbox in project configuration tab in eclipse. As my library project has a AndroidManifest.xml, it can be executed if i unmark that checkbox.
Now i'm trying to achieve the same in AndroidStudio but i am facing a problem. I don't know how to switch easily a project to change between application project and library project, and also AndroidStudio it is giving me a lot of errors because it detect duplicated items between my library project AndroidManifest.xml and my launcher project AndroidManifest.xml when I try to compile my launcher project referencing my library project...
Any help will be grated..
Thanks
I would say that in the build.gradle file you can specify if the module is an app or a library
If the module is an app you must specify
apply plugin: 'com.android.application'
If it's a library
apply plugin: 'com.android.library'
Remove lib's dependence before change your build.gradle.
compile project('xxx')