Android studio, migrating gradle project to version 1.0 - android

I want to migrate gradle project in Android Studio to version 1.0.
I have the next problem:
Warning:Project app: Only Jar-type local dependencies are supported. Cannot handle: /home/jaume/android-studio-0.8.14/projects/Rutacomandero/app/libs/google-gson-1.7.1-release.zip

Assuming "google-gson-1.7.1-release.zip" is just the gson dependency, then include it in your dependencies section of your build.gradle file, like so:
compile 'com.google.code.gson:gson:1.7.1'
You should be depending on jar files, not zips, and in the case of gson, grab it from central rather than keeping a copy in libs.
Also, 1.7.1 is old, since you're upgrading anyway, try 2.3.1

Had the same problem and I was able to resolve it by adding
repositories {
mavenCentral()
}
so use:
repositories {
mavenCentral()
}
dependencies {
compile 'com.google.code.gson:gson:2.5'
}
I exampled version 2.5 but you should check for updates. see https://github.com/google/gson/releases
My answer was found at http://www.javacodegeeks.com/2013/08/getting-started-with-google-gson.html

Related

Android Studio fails to resolve repository

In my project, I'm trying to use the design support library. I have in my Gradle file:
dependencies {
....
compile 'com.android.support:design'
....
}
And when I try to build this, I get the error:
Normally I would just click Install Repository and sync project, however, this seems to not work anymore. Clicking this does absolutely nothing, even though clicking Open File works fine.
How can I manually install it?
I have the latest Android Support Repository (30.0.0), and Android Support Library (23.2.1) installed.
For me the solution was to add maven in the allprojects section. From the setup document: https://developer.android.com/topic/libraries/support-library/setup.html
in the project level settings.gradle file.
allprojects {
repositories {
jcenter()
maven{
url "https://maven.google.com"
}
}
}
Then double check the document for the latest version.
In the app level of the settings.gradle file add:
dependencies{
compile 'com.android.support:design:26.0.1'
}
And use Gradle to sync the project.
I think it is because you've not specified the version.
compile 'com.android.support:design:23.1.1'
change version to what you have downloaded.
You can go File->Settings->Gradle Look at the "Offline work" inbox,
If it's checked you can uncheck and try to sync again.

Share compile dependencies across modules

I have an android project with two modules. Both modules depend on android support library. Currently the support library dependency is added to gradle scripts of both modules.
When I upgrade support library version, I have to upgrade the version in both gradle files. I may sometimes forget to do this in both files. So I need a way to declare the support version in a one common place.
This page describes one approach, where you declare the dependencies in a separate file and include it in the root gradle file.
This approach worked for me, but there are some limitations. For an example, if a new support library is available, in previous approach, android studio gave me an inspection warning that a newer version is available. With new approach, android studio no longer does that. Also, whenever you make a change in a gradle file, android studio asks for re-sync the project. But, if I made change to the separated gradle dependency file, android studio doesn't ask me to re-sync.
I tried to directly add the support dependencies to the dependencies section of the root gradle file like given below, but android studio gives me a warning.
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.5.0'
compile "com.android.support:appcompat-v7:23.2.1"
}
}
Warning:
Fix plugin version and sync project.
Does anyone know any other ways which I can declare dependencies in a central place?
The easiest thing to do is declare an extension variable in your buildscript block that manages the entire build. Let's take a Kotlin project, for example, where the version of kotlin must be consistent between all the build components. Here's a top-level build.gradle that defines the buildscript:
buildscript {
ext.kotlin_version = '1.0.1'
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.5.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
Notice that it defines ext.kotlin_version, then uses it below in the plugin dependency.
Then, in the main app module:
dependencies {
compile 'com.android.support:appcompat-v7:23.2.1'
compile 'com.android.support:design:23.2.1'
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
}
I can use the variable again to use the same version of the kotlin stdlib compile dependency. But I only had to define the version string in one place. ext is a special gradle way of declaring extra properties for gradle domain objects. Defining one in buildscript makes it visible elsewhere for use.

Android Studio warns that new version of library is available, but it's not there

In my Android Studio project, I get warnings like this - stating there's a newer version available. (gson: using 2.3.1 but 2.4 is available)
But when I then update my gradle file to use 2.4 instead:
compile 'com.google.code.gson:gson:2.4'
I get the error that this cannot be resolved:
(I also tried 2.4.0 without any improvement)
So - can anybody explain to me, why the new version is offered, but cannot be resolved? What am I missing?
Thanks!
Gson is a Java library that can be used to convert Java Objects into
their JSON representation. It can also be used to convert a JSON
string to an equivalent Java object.
You can use below Stable version
compile 'com.google.code.gson:gson:2.3'
Latest is Gson 2.6.1
compile 'com.google.code.gson:gson:2.6.1'
I have the same problem.
"Invalidate Caches / Restart" in Android Studio's File menu solve this.
As of Gradle 1.7, jcenter() is a superset of mavenCentral()
Jars will be downloaded from online central jcenter repository. so adding just the following statement is working.
dependencies {
compile 'com.google.code.gson:gson:2.2.+'
}
add repositories in your build.gradle, it will work
repositories {
mavenCentral()
}

I cannot use Android support libraries or Play Services via Gradle in one of my projects

I'm trying to add the support libraries to my app by putting this in the dependencies section of build.gradle:
compile 'com.android.support:appcompat-v7:20.0.+'
This works fine in all my libgdx apps except for one of them. It simply cannot find the library. It says:
Error:Could not find any version that matches com.android.support:appcompat-v7:20.0.+.
Searched in the following locations:
file:/C:/Users/MyName/.m2/repository/com/android/support/appcompat-v7/maven-metadata.xml
file:/C:/Users/MyName/.m2/repository/com/android/support/appcompat-v7/
https://repo1.maven.org/maven2/com/android/support/appcompat-v7/maven-metadata.xml
https://repo1.maven.org/maven2/com/android/support/appcompat-v7/
https://oss.sonatype.org/content/repositories/snapshots/com/android/support/appcompat-v7/maven-metadata.xml
https://oss.sonatype.org/content/repositories/snapshots/com/android/support/appcompat-v7/
https://oss.sonatype.org/content/repositories/releases/com/android/support/appcompat-v7/maven-metadata.xml
https://oss.sonatype.org/content/repositories/releases/com/android/support/appcompat-v7/
I tried this with the Android support libraries as well, and they have the same issue.
local.properties is pointing to the android sdk just as it is in my other projects.
I see that its searching the Android SDK's local Maven repository for it. But the directory as listed above in the error does not exist. The .m2/repository directory exists with some of my other local stuff, but not the android one. And since this is working fine in my other projects, I'm not sure what could be going on. Perhaps they are checking a different local Maven repository?
I recently installed Maven so I could create my own local repository for use when working on a library project. Maybe I somehow overwrote the original android directory? Doesn't explain why the other old libgdx projects are not failing to find the library though. How can I check where they are searching for it?
Here's the build script (generated by libgdx project generator):
buildscript {
repositories {
jcenter()
maven { url 'https://github.com/steffenschaefer/gwt-gradle-plugin/raw/maven-repo/' }
}
dependencies {
classpath 'de.richsource.gradle.plugins:gwt-gradle-plugin:0.4'
classpath 'com.android.tools.build:gradle:1.0.0'
classpath 'org.robovm:robovm-gradle-plugin:1.0.0-beta-01'
}
}
Here are relevant parts of build.gradle in top level of project and from the android module:
allprojects {
apply plugin: "eclipse"
apply plugin: "idea"
repositories {
mavenLocal()
jcenter()
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
maven { url "https://oss.sonatype.org/content/repositories/releases/" }
}
}
dependencies {
compile 'com.android.support:appcompat-v7:20.0.+'
compile 'com.android.support:support-v4:20.0.+'
compile 'com.google.android.gms:play-services:6.5.87'
}
Check you Android sdk folder.
You should find this folder under this:
androidSdk/extras/android/m2repository/com/android/support/appcompat-v7/20.0.0
If this folder doesn't exist:
update the SDK Manager and update the Android Repository (the last block).
Also I suggest you using the last releases:
compile 'com.android.support:appcompat-v7:21.0.3'
compile 'com.android.support:support-v4:21.0.3'
Please compile with this
compile 'com.android.support:appcompat-v7:20.0.0'
Instead
compile 'com.android.support:appcompat-v7:20.0.+'
Try adding the mavenCentral repo:
mavenCentral()
to your allprojects
allprojects {
apply plugin: "eclipse"
apply plugin: "idea"
repositories {
mavenCentral()
mavenLocal()
jcenter()
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
maven { url "https://oss.sonatype.org/content/repositories/releases/" }
}
}
dependencies {
compile 'com.android.support:appcompat-v7:20.0.+'
compile 'com.android.support:support-v4:20.0.+'
compile 'com.google.android.gms:play-services:6.5.87'
}
Sidenote: the support libraries have been updated (not sure if you need the most recent ones):
compile 'com.android.support:support-v4:21.0.3'
compile 'com.android.support:appcompat-v7:21.0.3'
First check whether you have updated 'Android Support Repository' and 'Android Support Library' in your Android SDK Manager. Once updated, you should be able to build with latest appcompat-v7, at this time 21.0.3.
It would be more tricky for older appcompat-v7 versions. We had the same problem before, we were using appcompat-v7:19.0.+ at the time. It appears that once you update Android Support Repository & Library from Android SDK Manager, which contains the source for your support libraries, there is no going back. Once updated, it will only contain the latest source for support libraries, which means your build will always fail unless you update your build.gradle to point appcompat-v7 to latest version.
I find it surprising that we cannot have multiple versions of appcompat available, like how the SDK manager handles the multiple version of Android SDK build tools.
Sounds support library not installed or not in the right path as Android Studio supposed, so double check:
Check your Android SDK location from: File->project Structure->SDK Location
Then go to SDK Location path to check if \extras\android\support\v7\appcompat available
If not available then start SDK Manager under SDK Location, install both Android Support Library and Android Support Repository under Extras
I eventually fixed this after uninstalling Android Studio and the previous beta version I had, as well as all copies of the Android SDK on my computer. Then I reinstalled a fresh copy of Android Studio with the SDK.
Since none of the project configuration changes I made helped, I think there was possibly some kind of internal configuration in Android Studio that made it point at the wrong Maven repository, possibly the Maven repository in an Android SDK somewhere that was no longer maintained.
I'm glad I didn't reconstruct the project from scratch (to find step-by-step what differed between the problematic project and others that did work). Much faster to reinstall Android Studio.

Use android-maps-utils in Android Studio

I am trying to use this library [1] in an Android project either with Android Studio or with ADT. But it doesn't work at all. In ADT I don't know how to handle gradle stuff and in Android Studio, when I try to "Import Project", I get the error "Could not find com.google.android.gms:play-services:3.1.36.
(don't have enough reputation to post picture, it's on imgur with xswZ3.jpg)
I am not familiar with gradle and I only have a vague idea of what it does but all I want is to use something like BubbleIconFactory f = new BubbleIconFactory(this) in my own project.
Any help is appreciated!
[1] https://github.com/googlemaps/android-maps-utils
Perhaps your problem is needing the repositories outside of the buildscript block.
The repositories internal to the buildscript is for managing the gradle dependency itself, I believe. Here's how I resolved my problem with google-maps-utils as a library dependency. Hopefully this helps. I included my maps and support-v4 libs too.
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.10+'
}
}
apply plugin: 'android'
repositories {
mavenCentral()
}
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
// Support Libraries
compile 'com.google.android.gms:play-services:4.1.32'
compile 'com.android.support:support-v4:19.0.1'
compile 'com.google.maps.android:android-maps-utils:0.3+'
}
com.google.android.gms:play-services:3.1.36 can be downloaded by going to your SDK Manager and installing the Extras->Google Repository package (you may want to install the Extras->Android Support Repository as well while you are there). These allow Gradle to automatically use these resources without the need for library projects or jars manually added to your project.
Add the following dependency to your Gradle build file:
dependencies {
compile 'com.google.maps.android:android-maps-utils:0.2+'
}
You'll need to install the "Google Repository" from the Android SDK manager.
See demo/build.gradle for an example.
You can, of course, copy the library directory and use it like any other Android library project.
Let me know if this helps!
Chris
Steps:
First File>Project Structure>Click Plus Button >Import Graddle Project>Select the file(library folder) from the location where downloaded>CLick Ok.
Add this code to dependencies to that app module build.gradle file(remember there are two build.gradle files) :
dependencies {
compile 'com.google.maps.android:android-maps-utils:0.4+'
}
Copy gradle.properties file contents of that Android-maps-util Library project app(found inside that project library folder) TO
gradle.properties file of your project(Simple copy and paste of content to the editor).
Click Sync Project with gradle files button. And you must be fine!

Categories

Resources