Build dependencies with gradle, Android Studio, ADT - java

I am developing Android app with gradle project. My teammates use ADT, and I do Android Studio and I would like to try my best not to force limiting IDE for others.
As far as I know, ADT needs to have local dependencies (.jar or local lib).
Also if I have main project and local library which contains same local jar files, it cannot build with gradle due to "IllegalArgumentException: already added".
Settings below works fine with gradle and Android Studio but not for ADT, support v13 is not found.
Is there any way to make build works for gradle, Android Studio and ADT ?
Please let me know if you need more information.
My project setting looks like
settings.gradle
include: ':MyProj'
include: ':libs:PagerSlidingTabStrip'
build.gradle (MyProj's)
.....
dependencies {
compile 'com.android.support:support-v13:13.0.+'
compile project(':libs:PagerSlidingTabStrip')
}
.....
build.gradle (PagerSlidingTabStrip's)
.....
dependencies {
compile 'com.android.support:support-v13:13.0.+'
}
.....

You will have to do the following:
Make an Eclipse project for MyProject and libs/PagerSlidingTabStrip
In MyProj, create a libs folder and dump in it both support-v13 and support-v4.
Do NOT change build.gradle to dep on the content of libs/ or you'll have a duplicate class file issue.
This is manageable if you have only one lib project and few dependencies. If your setup become more complex it'll become impossible to manage (hopefully by then we have Gradle support in Eclipse)

Related

Adding Java library into Android project as submodule gives library not found error

I'm trying to add a Java library (Maven project) into my Android project as a submodule. I'm using Android Studio.
P.S: For the simplicity of this question, I'll use samplelib as my library name.
What I did is:
1- git submodule add https://www.github.com/samplelib.git
2- Added the dependencies in my Android project's settings.gradle and app level build.gradle file
In build.gradle (app)
implementation project(':samplelib')
In settings.gradle
include ':samplelib'
But it doesn't work. I'm getting errors like samplelib not found
I have tried this for android libraries before and it works but it's not working for Java libraries. Any suggestions?

External library dependency under Android Studio

I have my Android Studio project structured as follow:
/mysdk
-manifests
-java
-com.xxx.sdk
-ext-libs
-com.yyy.lib (not .jar but .java files instead)
-res
/app
-manifests
-java
-res
I can include com.yyy.lib.* inisde com.xxx.sdk and reference all the methods without any symbol resolution problem in Eclipse project.
But after I transfer my IDE from Eclipse to Android Studio and it tells me it cannot resolve the symbols/methods from com.yyy.lib inside com.xx.sdk (ex: com.xxx.sdk.Activty.java)
How can I fix this dependency problem in Android studio?
If you have no strong preference for the location of com.yyy.lib, just moving it into the parent (is it src/main/java? based on gradle convention) it will probably get picked up.
It appears the IDE is treating src/main/java (or whatever) as a source folder and your package paths aren't matching up with your directory structure
ext-libs.com.yyy.lib instead of com.yyy.lib
That's because Android Studio uses Gradle as its dependency manager, whereas Eclipse uses either Maven or Ant.
You can read more about managing dependencies with Gradle, here.
This answer explains how to add a dependency/library to Gradle in Android Studio.
In your project file browser:
Go to libs folder. and add your library if not present
and then in gradle: add compile files('libs/your_library') in dependencies and then Sync Gradle

How can I bring Google play services into my libGDX Gradle project?

After adding Google Play Services to integrate Google ads into my libGDX project in Eclipse, I can no longer use Gradle to build my Android project.
I know that's because I need to tell Gradle about the new Google Play project dependency so I added compile com.google.android.gms:play-services:5.0.89 to the dependencies section of the :android project however it complains that it could not find com.android.support:support-v4:19.1.0.
I guess that means I need to somehow tell Gradle this new dependency depends on another dependency?
Everything works fine in Eclipse so the dependency of my Google Play project in Eclipse is for sure golden, I just need to make Gradle the same way. Do I need to declare the Google play project as another Gradle project and make a build.gradle file for it? I don't think I should be touching the Google Play project contents at all.
If you have downloaded the tools and google reprositories using the Android SDK Manager (1st thing to check), check if your build.gradle files do not need to be updated (what libGDX version are you currently using?).
I had the same problem and solved it by replacing my Android's module build.gradle file by a brand new.
To do so, use the last ligdx setup ui (https://github.com/libgdx/libgdx/wiki/Project-Setup-Gradle) to create a fresh project then compare/replace gradle files.
Under your android module there's a build.gradle file. Add the following:
dependencies {
compile 'com.google.android.gms:play-services:6.1.11'
}
Check for the latest version of Google Play Services and update your version number accordingly.

android studio java.lang.NoClassDefFoundError Gson

I've made pretty much a fresh project. I added in the gson library by google to my projects /libs directory and added it as a library. I also added it into my build.gradle as
compile files('libs/gson-2.2.4.jar')
So now everything looks ok, there aren't any errors given by Android Studio, no red underlines anywhere. I can build it and give it a shot.
But then I run into this error:
java.lang.NoClassDefFoundError: com.google.gson.Gson
Which I can see in the debugger. The thing is i've added it in and android studio can see that but come build it gives me all these sorts of problems.
What am I doing wrong?
Had the same issue. What I did was gradle clean and then build my project with gradle from console. In my build.gradle gson dependency looks like this:
dependencies {
compile 'com.google.code.gson:gson:2.2.4'
}
Something went wrong in incremental build system. One of this should help:
Menu Build -> Rebuild project
Delete folder /build
Close Android Studio, delete /build folder
Right click on your project -> "Open module settings" -> Dependencies tab -> check if Export is checked for your library
I'm using Android Studio. and in my case, gradle clean and/or Rebuild project didn't work.
I had to uninstall the current SDK (in my case: 22) that was supposed to be corrupted and then reinstall it. After doing this, the project restarted to compile and run. Hope it can help someone.

JAR libraries not being detected

I created a fresh project in Android Studio which uses external library (JAR). I put this in modules's build.gradle:
dependencies {
compile files('libs/android-support-v4.jar')
compile files('libs/mylib.jar')
}
But, when using Android Studio editor, it says there are some errors in my code and marks imports and variables (which use this library). It doesn't build properly saying that it cannot find one or another class. However, when I go to project's directory in terminal and execute gradlew manually, it builds APK and it (the APK) install and works just fine.
What am I missing? Is there any another setting in my project which is used for library detection?
Android Studio currently does not automatically sync your Gradle build files with your Android Studio (.iml) files. However, version 0.1.3 added a new sync button to the toolbar that will do this manually.
It's mentioned in the second bullet point of this blog post.
There were a lot of fixes in the Gradle project import and build
areas. There is now a "sync" button in the toolbar which will reimport
the Gradle project state into your Android Studio project. Use this
after editing your Gradle files, for example to add a library. In the
future we will more automatically handle state syncing, but for now
this is the simplest way to keep the IDE up to date with project
structure changes made to the Gradle files.

Categories

Resources