How to convert android studio app project into an android library - android

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.

Related

Android convert project to library project

I am trying to convert an Android Studio project as a library.
What is the best way to do this and the steps I need to follow?
What file can I remove from that library project, so that the library look cleaner?
An Android library is structurally the same as an Android app module. It can include everything needed to build an app, including source code, resource files, and an Android manifest. However, instead of compiling into an APK that runs on a device, an Android library compiles into an Android Archive (AAR) file that you can use as a dependency for an Android app module. Unlike JAR files, AAR files can contain Android resources and a manifest file, which allows you to bundle in shared resources like layouts and drawables in addition to Java classes and methods.
Convert an app module to a library module
Open the build.gradle file for the existing app module. At the top, you should see the following:
apply plugin: 'com.android.application'
Change the plugin assignment as shown here:
apply plugin: 'com.android.library'
Also in this file, you have to delete this line
applicationId "your.application.id"
Click Sync Project with Gradle Files.
Check this for more details https://developer.android.com/studio/projects/android-library.html
You need to do THREE things :
1- change the apply plugin: 'com.android.application' in the build.gradle of the module to apply plugin: 'com.android.library'
2-delete applicationId "your.application.id" in the module's build.gradle
3-remove <application and it its content from your module's AndroidManifest.xml file
4-also remove the resources in mipmap directories and the themes and colors.xml (or any other resource file that might conflict with the parent or app module) to avoid any surprises and crashes when using this library module from a module that has the same files.(I have wasted 4 hours to know the reason of app crash at startup with no helpful logs).

Integrate MemorizingTrustManager library in Android Studio Project

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

How to Create a SDK in Android Studio form the app

I have a Android app and now I have to make a SDK form the app. So other apps can use my SDK by just putting a compile time dependency I dont find many sources in Internet can some one please help me in this regard.I am using Andorid Studio
I want to build a SDK similar to MobiHelp SDK see this link : https://github.com/freshdesk/mobihelp-android
If your SDK is an Android-Library, declare
apply plugin: 'com.android.library'
instead of
apply plugin: 'com.android.application'
in the corresponding build.gradle. You will get an .aar-File (Android ARchive) that would need to be refereced from others in order to use your SDK.
If your SDK is a plain-old-java-Library (no Android resources) you also can use Maven to package it as jar.

Android Studio -> How to Switch a project between Library project and Application project?

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

Android studio- Can't run library project?

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

Categories

Resources