Android 3rd Party Library Integration - java

this is kinda crazy. I already worked often with 3rd party librarys. All I had to do was adding the compile command in the build gradle but in this case its something different. This is the github link of the lib i want to implement:
Link to github
I tried to integrate the files I need manually but i got a amount of errors.
In the README the developer says:
This library is provided as the AAR format. The source jar file won't be downloaded automatically (due to the current Gradle and Android Studio limitation), so javadoc comments are not displayed on IDE.
Can somebody help me how to integrate this the best way.

If you have a look below, they have already provided a workaround
buildscript {
repositories {
maven { url 'https://raw.github.com/xujiaao/mvn-repository/master/releases' }
}
dependencies {
classpath 'com.github.xujiaao:aarLinkSources:1.0.0'
}
}
apply plugin: 'com.android.application'
apply plugin: 'aar-link-sources'
android {
...
}
dependencies {
compile ('com.h6ah4i.android.widget.advrecyclerview:advrecyclerview:0.8.0#aar'){
transitive=true
}
aarLinkSources 'com.h6ah4i.android.widget.advrecyclerview:advrecyclerview:0.8.0:sources#jar'
}

Related

Create single AAR file from multiple modules using Gradle in Android Studio [duplicate]

I am building android library project, which has a dependency on another internal library project.
I am wondering if there is a way to package a single AAR library, which already contains internal library inside it. I would like to share only 1 AAR library package to my application developers.
This is how my build.gradle files look currently, but currently they produce separate AAR files and both needs to be included in Application's build.gradle. As application is being built by another company, we need to share the final AAR file with them and not the complete library projects.
----- internalLib -------->>>>>>>>>>
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.7.+'
}
}
apply plugin: 'android-library'
repositories {
mavenCentral()
}
android {
compileSdkVersion 18
buildToolsVersion '18.1.1'
}
dependencies {
compile 'com.android.support:support-v4:18.0.0'
}
----- externalLib --------
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.7.+'
}
}
apply plugin: 'android-library'
repositories {
mavenCentral()
}
android {
compileSdkVersion 18
buildToolsVersion '18.1.1'
}
dependencies {
compile 'com.android.support:support-v4:18.0.0'
compile project(':internalLib')
}
There is no mechanism to combine library. It's a bit complicated as you probably want to control which dependencies get merged (for instance you probably don't want to include support-v4 in there). Also you'd need to merge the resources and Android manifest.
At this time there's no way to easily hack something, unless you are sure the resources have no conflicts between the two res folders (for instance you could have strings_a.xml in one lib and strings_b.xml in the other lib). This way you can just "merge" the two res folders by copying them both into the same location (as opposed to do a merge at the android res level).
For the Manifest it'd be more complicated, but doable with some custom code.
Providing a built-in mechanism for this is very low on our priority so don't expect it anytime soon.
For the sake you have to upload each library as separately on maven and use its implementation in parent library modules till the main library module. Only then when you publish your main library on maven will include your all child dependencies.
As far as we have only one option add aar as api dependency inside the module.
For that we have to generate aar file and publish it to Maven and make it accessible by another module and consume it in app.
https://developer.android.com/studio/projects/android-library
As mentioned above android developer document.
The library module with source code 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.
If there anything else we can do, please let us know by jot down in the command section.
It is not supported
It is not recommended to include one library into another because it leads to a serious issues with managing versions and complexity of creating and supporting such solution.
You should stick to native approaches like dependency manager or rearchitect your codebase
[iOS Umbrella framework]

Missing Android-support-v7-appcompat in my Android project in Eclipse

I am trying to import an Android project in Eclipse., but after importing the project, I am getting errors which say "Missing android-support-v7-appcompat", "Missing Facebook SDK","Missing Google Play services lib" and "Missing library".
I can understand that I am missing libraries but do not have any clue how to add those libraries, as I am new in Android development environment.
Here, is a screenshot of the error http://screencast.com/t/iWXLkK8glkF
Delete the extra apply in the first line of your gradle file...
UPDATE:
You know how you have two gradle files? One for your application (The one you are working on right now) and the other one which is a top level build.gradle file? Put the below code in the top level build.gradle file:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.3.0'
}
}
allprojects {
repositories {
jcenter()
}
}

How can I use an application from another project as a library?

How can I use an application from another project as a library, when that application depends on a library that I am already using?
Here’s what I have:
MyProject
app
libraries
ExoPlayer
demo
library
Here's my current configuration as it pertains to this.
demo/build.gradle:
apply plugin: 'com.android.application'
...
dependencies {
compile project(':library')
}
library/build.gradle:
apply plugin: 'com.android.library'
MyProject/settings.gradle:
include ':libraries:ExoPlayer:library'
MyProject/app/build.gradle:
dependencies {
compile project(':libraries:ExoPlayer:library')
}
As you can see I’m using ExoPlayer library as a library (go figure) but I want to use demo application as a library as well (specifically for the DemoPlayer, I don't want the activities). But demo also has a dependency on library. What do I have to put in my gradle files to achieve this?
I tried to follow the library setup and apply it to demo but it broke the demo build:
Project with path ':library' could not be found in project ':libraries:ExoPlayer:demo'
I have tried following other similar threads such as this one but with no success.
I appreciate any help.
A long time ago I've use Exoplayer as a library project but it's not needed anymore : you can use gradle dependencies :
compile 'com.google.android.exoplayer:exoplayer:r1.4.2'
If you want to persist with library project, you will have to check your settings.gradle where all Android Studio referenced module are in. This file contain the name of module as you will use it after.
Example : (based on AndroidVuMeter)
settings.gradle
include ':app', ':vumeterlibrary'
project structure
Project/
app/
vumeterlibrary/
To use vumeterlibrary you will have to use compile project(':vumeterlibrary') in your app build.gradle

Cannot Resolve ContextCompat in Android

I have an AlertDialogue object called dialog. I am attempting to add an icon to it. I see that this syntax is now deprecated:
dialog.setIcon(getResources().getDrawable(R.drawable.myImage);
I'm reading everywhere that this should work:
dialog.setIcon(ContextCompat.getDrawable(context, R.drawable.myImage));
However, the ContextCompat syntax is not being recognized by Android Studio. Is there something that I should be importing? Thank you.
***Update: Thank's to #Sharj for the correct answer below. I made a quick video too if you guys need a visual: https://www.youtube.com/watch?v=eFiaO0srQro&feature=youtu.be
ContextCompat is part of support library v4. Have you added support library 4 to your project?
android.support.v4.content.ContextCompat
You can include support library to your build.gradle file under app folder if you haven't already
dependencies {
// other stuff here
compile 'com.android.support:support-v4:23.0.0'
// update the 23.0.0 to latest version available
}
androidx.core.content.ContextCompat
from AndroidX dependency
implementation 'androidx.appcompat:appcompat:1.1.0'
I had the same issue and this and a few more posts helped me.
With Android studio you have multiple Gradle files.
I got my code to work by adding the dependencies section into Gradle (Module : Library) or the file that has "android {" ...
dependencies {
// other stuff here
compile 'com.android.support:support-v4:23.+'
// update the 23.0.0 to latest version available
}
If you are using Android gradle plugin 3.0.1, add google() to your allProjects repositories in the build.gradle file (project level) then sync
like this:
allprojects {
repositories {
google()
....
//other repos
}
}
Adding this to build.gradle(Module:App) under dependencies resolved the problem
compile 'com.android.support:support-v4:23.0.0'

How can I add a linked source folder in Android Studio?

In Eclipse I can add a source folder to my Android project as a "linked source folder". How do I achieve the same thing in Android Studio?
Or is it possible to add an external folder to build in Gradle?
In your build.gradle file, add the following to the end of the Android node:
android {
....
....
sourceSets {
main.java.srcDirs += 'src/main/<YOUR DIRECTORY>'
}
}
The right answer is:
android {
....
....
sourceSets {
main.java.srcDirs += 'src/main/<YOUR DIRECTORY>'
}
}
Furthermore, if your external source directory is not under src/main, you could use a relative path like this:
sourceSets {
main.java.srcDirs += 'src/main/../../../<YOUR DIRECTORY>'
}
You can add a source folder to the build script and then sync. Look for sourceSets in the documentation here: http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Basic-Project
I haven't found a good way of adding test source folders. I have manually added the source to the .iml file. Of course this means it will go away everytime the build script is synched.
While sourceSets allows you to include entire directory structures, there's no way to exclude parts of it in Android Studio (as of version 1.2), as described in Exclude a class from the build in Android Studio.
Until Android Studio gets updated to support include/exclude directives for Android sources, symbolic links work quite well. If you're using Windows, native tools such as junction or mklink can accomplish the equivalent of symbolic links on Unix-like systems. Cygwin can also create these with a little coercion. See: Git symbolic links in Windows and How to make a symbolic link with Cygwin in Windows 7.
Here’s a complete Java module Gradle file that correctly generates and references the built artefacts within an Android multi-module application:
buildscript {
repositories {
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath "net.ltgt.gradle:gradle-apt-plugin:0.15"
}
}
apply plugin: "net.ltgt.apt"
apply plugin: "java-library"
apply plugin: "idea"
idea {
module {
sourceDirs += file("$buildDir/generated/source/apt/main")
testSourceDirs += file("$buildDir/generated/source/apt/test")
}
}
dependencies {
// Dagger 2 and Compiler
compile "com.google.dagger:dagger:2.15"
apt "com.google.dagger:dagger-compiler:2.15"
compile "com.google.guava:guava:24.1-jre"
}
sourceCompatibility = "1.8"
targetCompatibility = "1.8"
This is for Kotlin DSL (build.gradle.kts):
android {
sourceSets["main"].java.srcDirs("src/main/myDirectory/code/")
sourceSets["main"].resources.srcDirs("src/main/myDirectory/resources/")
// Another notation:
// sourceSets {
// getByName("main") {
// java.srcDirs("src/main/myDirectory/code/")
// resources.srcDirs("src/main/myDirectory/resources/")
// }
// }
}
If you're not using Gradle (creating a project from an APK, for instance), this can be done through the Android Studio UI (as of version 3.3.2):
Right-click the project root directory and pick Open Module Settings
Hit the + Add Content Root button (center right)
Add your path and hit OK
In my experience (with native code), as long as your .so files are built with debug symbols and from the same absolute paths, breakpoints added in source files will be automatically recognized.

Categories

Resources