i'm working with android studio and i have an issue... i import 2 libraries (facebook SDK and Aws) that both use and import the android support v4 libs, doing that gradle can't compile anything giving a bad top-level exception (dexDebug).
In others answer i saw that i can solve this situation in 2 ways, removing one of the libs (but i can't because i need both) or using the "multipledex = true" in build.gradle that give me another error for the length of the command.
So, what i should do? Shall i stop using AS and go back to Eclipse? Or anybody have a solution?
Thanks,
Andrea
Don't import the support library by copying its jar as you used to in Eclipse. In Gradle, access it via its Maven coordinates and the build system will ensure that only one copy gets linked into your project:
dependencies {
compile 'com.android.support:support-v4:X.X.X'
}
where X.X.X is the right version number for your SDK installation. If you manage the dependency via Project Structure > (your module) > Dependencies > + > Library dependency it will help you get the version number right.
Related
I'm trying to integrate Google Play Games in a libgdx project.
All the tutorials found around the internet are either old or incorrect, also they're based on Eclipse.
My problem is that it seems like the BaseGameUtils module won't compile due to some incompatibility, which I'm not able to undestand.
The procedure I've followed is the standard one:
1) I've downloaded the BaseGameUtils module, available here
2) I've imported it as a module in my project with File -> New -> Import Module...
3) I've added the dependency in my build.gradle (Module:android) as
dependencies {
compile 'com.google.android.gms:play-services-games:8.4.0'
compile(':BaseGameUtils')
}
When I try to sync and build, I'm getting this error:
Error:(5, 5) uses-sdk:minSdkVersion 1 cannot be smaller than version 7 declared in library [my game path]\BaseGameUtils\build\intermediates\exploded-aar\com.android.support\appcompat-v7\20.0.0\AndroidManifest.xml
How can I fix that? Any help would be really appreciated!
The error suggests that you have a smaller sdk version decalred than the one your library supports.
Try modifying the minSdkVersion on your Gradle file so that it matches the one your library requires. (In your case 7).
I used libgdx to build my project and I am having issues using the JSONObject class. When I add import org.json.JSONObject, it says it cannot resolve. How do I add that library to my project?
Here is what I have tried without success:
I downloaded the json-simple-1.1.jar and put it in core/build/libs folder. Could not use import.org.json.simple.JSONObject either.
When browsing the tree in Android Studio as "Packages" dropdown, I can see the classes I want under "Core -> Libraries -> org -> json" but I cannot add them to my project. I get a "cannot refractor, class is in a jar file" error.
Is there something I have not tried yet to solve this issue? I feel I will run into this again as I try to use other external libraries.
Thank you.
If you are using LibGdx, it does not come with a Gradle setup, making multi-project builds streamlined.
You need to add implementation 'org.json:json:<version>' to the dependencies block of your top-level build.gradle.
To find the latest version, see http://mvnrepository.com/artifact/org.json/json/
For example, using the latest version at the time of writing:
dependencies {
implementation 'org.json:json:20200518'
}
I'm trying to implement a Facebook Like Button in an app and I just found a good library: Facebook Like Button by shamanland.
Now the problem is that I'm using Eclipse and I can't figure out how to import this project correctly in order to use it in the app.
Can anyone help?
Thanks!
That project uses the gradle build system, but eclipse uses the ant system.
Google is leaving ant and migrating to the new gradle system which is used with their new Android Studio IDE. Most of the new libraries also are migrating to gradle due to easy dependency management.
This is a good time to migrate your project to Android Studio.
Download it and when you import your project, it will automatically convert it to gradle.
Then you can easily add gradle libraries to your project's build.gradle, and it will take care of downloading and maintaining them.
For this particular library, you have to add the following to your build.gradle:
repositories {
mavenCentral()
}
dependencies {
compile 'com.shamanland:facebook-like-button:0.1.6'
}
You can also download the Gradle plugin for Eclipse, but it may not be fully compatible with ADT. It's better to use the Android Studio and avoid the headache.
More Info Here
You may download compiled aar file from the Maven Cental.
Just import this aar into your Eclipse project as standalone library.
I am switching from Eclipse to Android Studio. I have couple of 3rd party libraries that I have added features or modified a little bit. Since the libraries in Eclipse are also projects and we can access the code, I had no problem.
In Android Studio compile tag in dependencies is great but in my case I cannot use it unfortunately.
I fork the project and made necessary changes and add the project as a module in Android Studio. Since the library project already has settings.gradle and example and library modules, there is a mess in my project and it does not compile at all.
Has anybody experienced such a problem? What to do and what is the correct way to forked libraries?
What we've done in my project is create gradle scripts for our dependencies that don't have them, and modify the gradle scripts for dependencies that do have them. Gradle does not play very well with modular dependencies, unfortunately: Each sub-project must know its place in the larger overall project. Since you've already forked the github project, modifying it further shouldn't be a problem.
I'm using Android Studio with an external Android SDK. I have installed the support library and the support repository. The support repository is in:
~/Development/Tools/android/sdk/extras/android/m2repository
When I add a dependency to the support library in the build.gradle file, like:
...
repositories {
mavenCentral()
}
...
dependencies {
compile "com.android.support:support-v4:18.0.+"
}
Android Studio cannot find the support libraries (cannot resolve symbol etc) and Gradle also cannot find the libraries:
Gradle: A problem occurred configuring project ':TestAndroidStudio'.
> Failed to notify project evaluation listener.
> Could not resolve all dependencies for configuration ':TestAndroidStudio:_DebugCompile'.
> Could not find any version that matches com.android.support:support-v4:18.0.+.
Required by:
TestAndroidStudio:TestAndroidStudio:unspecified
How do I specify in Android Studio and/or the build.gradle file the location of the Android support repository?
You are probably hit by this bug which prevents the Android Gradle Plugin from automatically adding the "Android Support Repository" to the list of Gradle repositories. The work-around, as mentioned in the bug report, is to explicitly add the m2repository directory as a local Maven directory in the top-level build.gradle file as follows:
allprojects {
repositories {
// Work around https://code.google.com/p/android/issues/detail?id=69270.
def androidHome = System.getenv("ANDROID_HOME")
maven {
url "$androidHome/extras/android/m2repository/"
}
}
}
Gradle can work with the 18.0.+ notation, it however now depends on the new support repository which is now bundled with the SDK.
Open the SDK manager and immediately under Extras the first option is "Android Support Repository" and install it
Found a solution.
1) Go to where your SDK is located that android studio/eclipse is using.
If you are using Android studio, go to extras\android\m2repository\com\android\support\.
If you are using eclipse, go to \extras\android\support\
2) See what folders you have, for me I had gridlayout-v7, support-v4 and support-v13.
3) click into support-v4 and see what number the following folder is, mine was named 13.0
Since you are using "com.android.support:support-v4:18.0.+", change this to reflect what version you have, for example I have support-v4 so first part v4 stays the same. Since the next path is 13.0, change your 18.0 to:
"com.android.support:support-v4:13.0.+"
This worked for me, hope it helps!
Update:
I noticed I had android studio set up with the wrong SDK which is why originally had difficulty updating! The path should be C:\Users\Username\AppData\Local\Android\android-sdk\extras\
Also note, if your SDK is up to date, the code will be:
"com.android.support:support-v4:19.0.+"
Android Studio 3
Make sure you have the latest version of Android Studio. The support library is included by default when you create new projects. If you are adding the Support Library to a project that doesn't have it, then you just need to add a single line to your app module's build.gradle file, and then sync gradle.
build.gradle
dependencies {
...
implementation 'com.android.support:appcompat-v7:27.1.1'
}
It should just be that easy, though there may be some things to note:
Android Studio should give you a warning nowadays if the support library needs to be updated. Just update the 27.1.1 numbers that I have here to whatever it tells you to. You can also manually check what the latest revision is if you want to.
The implementation keyword replaces compile that was used in Android Studio 2.x. (What's the difference?)
There are other support library packages that you may need to include depending on what your app uses (like constraint-layout or recyclerview).
Make sure that you have the latest updates for everything in the SDK Manager. Go to Tools > SDK Manager.
Documentation
Support Library
Support Library Setup
Support Library Features
I used to get similar issues. Even after installing the support repository, the build used to fail.
Basically the issues is due to the way the version number of the jar files are specified in the gradle files are specified properly.
For example, in my case i had set it as "compile 'com.android.support:support-v4:21.0.3+'"
On removing "+" the build was sucessful!!
Instead of doing this:
compile "com.android.support:support-v4:18.0.+"
Do this:
compile 'com.android.support:support-v4:18.0.+'
Worked for me