Bundle third-party library in my .aar - android

I'm building an Android library for music streaming. It has ExoPlayer as dependency (excellent library btw!).
We use this library for another project that we're also developing right now, in Xamarin. Currently, we need to add both libraries (my .aar and a .jar for ExoPlayer). That's a bit annoying to be honest, I'd love to just drop my .aar in, and go.
So two questions:
is there a way I can bundle the ExoPlayer inside my .aar, using gradle and stuff? (I'm quite a beginner here, be thorough please)
I realise it might not be the best thing to do (dependency should be managed by app, blah blah blah), but really we will always test ExoPlayer and my lib together every time we update the former. So is there a strong reason I should not bundle ExoPlayer in my lib, or is that ok?
And here's my current gradle file. Nothing exciting to look at though. But as I converted the initial app to a lib, maybe there's something odd, who knows...
apply plugin: 'com.android.library'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
minSdkVersion 19
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile ('com.google.android.exoplayer:exoplayer:r1.5.6')
testCompile 'junit:junit:4.12'
testCompile 'org.mockito:mockito-core:1.10.19'
compile 'com.android.support:appcompat-v7:23.2.0'
}

There are no solutions for this until this issue is solved, but a viable alternative for someone can be to bundle the .aar(s) singularly using the "Import .JAR/.AAR Package" while clicking on "New Module".
The only problem with this approach is that you can bundle only 1 AAR at a time in this way, so you need to create a module for each one of them.
In alternative you can try with Kezong fat aar library:
https://github.com/kezong/fat-aar-android

Related

Release APK seems to break Firebase functionality

I've been working on a Firebase-based social app for a while. The app was coming along fine, when I noticed everybody (except for me) kept getting inexplicable crashes. I assumed it was because the app was built around open source code, so I started anew from scratch. Again, the app was coming along fine, but as soon as I published it, similar inexplicable crashes started occuring. At this point I realised the crashes only occured in the release APK. As far as I can see, all of these crashes are related to Firebase. Most of them are NullPointerExceptions where some data is Null in the release APK, but not Null in the test version with the exact same use case.
I managed to solve one of these mysterious crashes by correctly implementing multidex (I didn't implement this correctly before and I think this caused one of the problems). Problems still remain though. I've completely turned of ProGuard, because I suspect that may be one of the problems. ProGuard was disabled before, but now I added these lines, just to be sure:
-dontoptimize
-dontshrink
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-dontpreverify
-verbose
Still crashes.
This is becoming a bit of a problem. What could possibly solve this problem?
Here's my Build.gradle.
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.0.0"
defaultConfig {
applicationId "app.id"
minSdkVersion 16
targetSdkVersion 25
versionCode 16
versionName "0.0.16"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
renderscriptTargetApi 24
renderscriptSupportModeEnabled true
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
dataBinding {
enabled = true
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:multidex:1.0.1'
compile 'com.android.support:recyclerview-v7:25.3.1'
compile 'com.android.support:design:25.3.1'
compile 'com.android.support:support-v4:25.3.1'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'com.google.android.gms:play-services:11.0.1'
compile 'com.google.firebase:firebase-messaging:11.0.1'
compile 'com.google.firebase:firebase-auth:11.0.1'
compile 'com.google.firebase:firebase-database:11.0.1'
compile 'com.google.firebase:firebase-storage:11.0.1'
compile 'com.firebaseui:firebase-ui-auth:2.0.1'
[loads more dependencies]
testCompile 'junit:junit:4.12'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.6.0'
}
apply plugin: 'com.jakewharton.butterknife'
apply plugin: 'com.google.gms.google-services'
The problem has gone away on a fresh project. Here's the things I've done to avoid this.
Switched to Android Studio 3.0 (Canary 7), including the new build tools
Switched to Kotlin as my main project language
Made sure my project's build.gradle gave no error notifications about different versions (using the project files view). Firebase UI caused one of these errors.
Avoided MultiDex alltogether
Either one of these may have solved the problem. I'm not sure how long I can avoid using multidex, but I'll update this answer if I find out MultiDex is the problem and / or find an alternative solution.

Visual Studio: Where can I edit the dependencies of my android app?

I'm right now at monetizing my app. In order to do this, I need to do the following:
Import the Mobile Ads SDK
Apps can import the Google Mobile Ads SDK with a gradle dependency. Open the app-level build.gradle file for your app, and look for a "dependencies" section.
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:25.3.1'
compile com.google.android.gms:play-services-ads:10.2.4'
}
I can absolutely NOT find this page where I can edit the dependencies. Can anyone hint me towards the right direction? THANKS :)
In Xamarin the dependencies need to be binded to C#. Luckily you do not have do that on your own for the Android Support AppCompat v7 and Play Services Ads because there are nuget packages:
https://www.nuget.org/packages/Xamarin.GooglePlayServices.Ads/
https://www.nuget.org/packages/Xamarin.Android.Support.v7.AppCompat/
Just right click "References" in your Xamarin Android project and click "Manage NuGet Packages" and install the packages mentioned above or make use of the package manager console.
Inside your App Module you can find build.gradle file there you can write your dependency as.
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
applicationId "com.example.satyamanand.helloworld"
minSdkVersion 15
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:25.3.1'
testCompile 'junit:junit:4.12'
}
Inside Android Studio checkout the application Structure.
You can't find Gradle dependencies because you're not using Gradle, you're using xamarin which is not the same as native Android Development using Android Studio.
Looking at and Android Docs for this sort of thing will perhaps not be so useful.
I suggest you look here at the Xamarin Google Play Services module, this should get you started in the right direction.

Add AppCompat dependency to Gradle in Android Studio

Verdant newbie here. I'm making a fairly simple project that needs to be compatible with Android versions older than Lollipop, but still want to have the app look nicer by using AppCompat.
Unfortunately, I do not know how to work (or even find) the gradle - I tried to run a gradle task: compile "com.android.support:appcompat-v7:21.0.+"
But it returned an error saying that "Task 'compile' is ambiguous...." in my project.
Could anyone tell me how to add this? I've searched all over Google, but everything goes way over my head.
Thanks!
Have you been able to locate Gradle file?
Edit your gradle like this :
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
defaultConfig {
applicationId "com.xyz.xyz"
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.00.00"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.3.0'
compile 'com.android.support:support-v4:23.3.0'
}
Update your question and post full Gradle code.
Add the appcomapt library(com.android.support:appcompat-v7:21.0.+") in dependancy section of the build.gradle file
Or second way to add library is by searching on maven repo.this can be done by traversing file->project structure->app>dependancy->click (+) ->add Library dependancy
Task 'compile' is ambiguous.
This issue is not the Compile Issue. but this was an issue on the task itself.
if you are not using a command like "gradle compileDebug" then one of the android configurations are executing the task and it is not working well with your build.gradle.
Here is a link that seems to relate specifically to your issue. Click Here

Self created library with dependency to another self created library

I am trying to build an app which is composed out of separate library projects.
To do this, I'm trying to make a proof of concept which is supposed to be as following:
I tried to keep the project as simple as possible. The projects contents do not matter!
All that matters is the dependencies between the projects!
The result should be that MainProject will print out Something Another String!
I have tried all from .JAR files to .AAR files, but the best I got was
with the dependency in red. I added the StringExtender.aar file to StringReturner, and then the StringReturner.aar file to the MainProject.
When I do this I get the following Exception:
java.lang.NoClassDefFoundError: Failed resolution of: Lcom/example/erik/stringextender/StringExtender;
What is the right way to setup a simple proof of concept like this? I can't seem to find anything related to a library project having a dependency. It's all 1 level deep!
Any help is welcome!
EDIT SHOWING GRADLE BUILD FILES
StringReturner:
apply plugin: 'com.android.library'
android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
defaultConfig {
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.2.1'
compile project(':StringExtender-lib-debug')
}
MainProject:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
defaultConfig {
applicationId "com.example.erik.erikpoc10"
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.2.1'
compile 'com.android.support:design:23.2.1'
compile project(':StringReturnerLib-debug')
}
Use the following tutorial - Creating libraries for Android applications
See a working example project on my Github
The most important steps taken were:
8.3. Create library module.
8.6. Define dependency to the library project.
Do not forget to import the library class you want to use, for example:
In MainProject: import com.example.stringreturner.StringReturner.
In StringReturner: import com.example.stringreturner.StringExtender.
The info below is based on the image you provided:
The library methods are not static so don't forget to make an actual object.
So StringReturner should make a StringExtender object, And MainProject should make a StringReturner object first!
And finally, I think it's a typo but both libraries have the class StringReturner. This will not work in the StringReturner library for obvious reasons.
I should also note that I used Android Studio 2.0 and I did not touch .JAR files nor .AAR files. I merely created two library modules and one app. Then configured the Project Structure -> Dependencies by adding Module Dependencies.

Android Studio can't find imported library

I've imported a library in Android studio (0.5.3)
My settings.graddle looks like this:
include ':app', ':libs:Android-PullToRefresh-master'
And my build.graddle looks like this:
apply plugin: 'android'
android {
compileSdkVersion 19
buildToolsVersion '19.0.1'
defaultConfig {
minSdkVersion 14
targetSdkVersion 19
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile 'com.android.support:appcompat-v7:19.+'
compile 'com.android.support:support-v4:19.+'
compile 'com.google.android.gms:play-services:4.2.42'
compile fileTree(dir: 'libs', include: ['*.jar'])
project(':libs:Android-PullToRefresh-master');
}
The folder I've downloaded is placed in the libs folder directly under the app folder. Also the graddle syncs and building doesn't provide any error. Yet whenever I try to import import com.handmark.xxxxxx; I get the error cannot resolve symbol 'handmark'. I've chcecked to project structure and the app has the dependency in the list.
What is going wrong and how can I fix this?
I ran into the same issue here and asked the question on the "Android Developer Tools" Google+'s community. Alex Ruiz picked up the conversation and told me:
I'm able to reproduce this issue. Unfortunately, no updates yet. We
are currently fixing the "Project Structure" (the core
infrastructure,) and we will get to this, hopefully soon.
So they are aware of it but we still have to wait until they fix it.
In the root of your project, run :
./gradlew clean && ./gradlew build
Then recompile your project in studio and you should see your new lib.
I had the exact same problem as this, however the library file was an aar file, and it happened a long time after adding the library and developing with it for a while.
Building on the information Thomas provided; I found to fix this you should replace the file dependency with a maven dependency if possible. A good resource for finding and creating your Gradle dependency is Gradle, please.
That site returns the below dependency when searching for PullToRefresh
dependencies {
compile 'com.loopeer.android.thirdparty.pulltorefresh:Android-PullToRefresh:2.1.1'
}

Categories

Resources