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
Related
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 am trying to create android aar which uses play services. I have added playservices dependency in library gradle file. But when aar is exported in release mode runtime it is not working.
How to add google play services in aar?
Please help
You may want to check these steps in adding your library as a dependency:
Add the library to your project in either of the following ways (if you created the library module within the same project, then it's already there and you can skip this step):
Add the compiled AAR (or JAR) file (the library must be already built):
Click File > New > New Module.
Click Import .JAR/.AAR Package then click Next.
Enter the location of the compiled AAR or JAR file then click Finish.
Import the library module to your project (the library source becomes part of your project):
Click File > New > Import Module.
Enter the location of the library module directory then click Finish.
The library module is copied to your project, so you can actually edit the library code. If you want to maintain a single version of the library code, then this is probably not what you want and you should instead add the compiled AAR file as described above.
Make sure the library is listed at the top of your settings.gradle file, as shown here for a library named "my-library-module":
include ':app', ':my-library-module'
Open the app module's build.gradle file and add a new line to the dependencies block as shown in the following snippet:
dependencies {
compile project(":my-library-module")
}
Click Sync Project with Gradle Files.
But, if it's an app module that you want to reuse, you can turn it into a library module by following these steps to convert an app module to a library module:
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'
Save the file and click Tools > Android > Sync Project with Gradle
Files.
For a more detailed information, see this documentation. Also. this related SO post can give additional insights.
As play-services now a days contains aar library instead of jar, we can not merge aar file with library i.e. another aar file. And, hence it is not possible to add play-services inside aar file. Best solution for this problem is who ever is using aar made by you, tell them to add play-services dependency in project.
Add a new module to your project and select import .JAR/.AAR Package.
After you added the module proceed like this : Project Structure → Select the app module → Dependencies tab → clieck the + button → select the module you added → Ok
I'm new to android.
I build a new project in android studio, but I can not sync the gradle.
I've searched and there were some recommendations which said the solution is making changes in module/build.gradle
I found two build.gradle but I don't know which one is module/build.gradle, however I did make change to both of them.(I added android method)
the first grdle file
second one
The tab you're looking is Project. It's like a File Explorer.
It says Project change it to Android from drop down menu.
That tab will have only the necessary files. There you will find both the Project gradle and module gradle.
The thing is you can find those files in Project also but it's easy and more convenient to work in Android Tab.
You not necessarily need to make changes to build.gradle in order to run a Gradle sync task. Let me first answer your first question:
I don't know which one is module build.gradle
When you crate a new Android studio project there are two build.gradle files you see. One in MyAppliaction/build.gradle and other is app/build.gradle.
Here MyAppliaction/build.gradle is the Project gradle file which is also called global gradle where you can configure project wide golbal configurations. As per your screenshot you have added depandencies{} in project build.gradle which is not correct(that's why your gradle sync is failed!), you can add depandencies object only in module build.gradle.
app/build.gradle is the "module" gradle file where you can configure module specific configs and dependencies. Module build.gradle will at least one for each module if you create one more library module in your project, that will have separate build.gradle.
but I can not sync the gradle
Yes, when you make any change to project or module build.gradle, you get a "Sync" button on top which can start gradle sync. But if you want gradle sync anytime just open on "Gradle" tab from right and click "sync" icon on top left. (see screenshot below)
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')
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