Adding Spring for Android into Android Studio project - android

I'm trying my hand at android development for the first time, and I'd like to create an app, "MyFirstApp", that's going to make calls to REST services. I did a little research and it looks like Spring for Android is a good tool to help me with this. I've never used Spring, and I'm not very familiar with Android Studio yet, so I'm confused how I should add the dependencies for Spring into my project.
Spring's website has a piece of code they say to copy and paste into my dependencies:
dependencies {
compile 'org.springframework.android:spring-android-rest-template:2.0.0.M3'
}repositories {
maven {
url 'https://repo.spring.io/libs-milestone'
}
}
I realize there's already a question posted that addresses a very similar issue, but I need help knowing EXACTLY which file to add the above code to, and EXACTLY where to do so.
I have two "build.gradle" files that were created in my project. First is
build.gradle (Module: app)
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "com.example.owner.myfirstapp"
minSdkVersion 15
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'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:design:23.1.1'
}
Second is build.gradle(Project: MyFirstApp)
// 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'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
dependencies {
compile 'org.springframework.android:spring-android-rest-template:2.0.0.M3'
}repositories {
maven {
url 'https://repo.spring.io/libs-milestone'
}
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Can anyone help show me where in these two files I should include the Spring dependency? I really appreciate any help.

Add this in build.gradle (Module: app) inside dependencies
compile 'org.springframework.android:spring-android-rest-template:2.0.0.M3'
Add this in build.gradle(Project: MyFirstApp) inside repositories
maven {
url 'https://repo.spring.io/libs-milestone'
}
That's it. You are good to go.

I don't know if you are behind a firewall, so this should really be a suggestion, but need to show formatted code:
Try replacing https with http here:
maven {
url 'http**s**://repo.spring.io/libs-milestone'
}
And add a url for jcenter:
repositories {
jcenter {
url "http://jcenter.bintray.com/"
}
}

You add the compile 'org.springframework.android:spring-android-rest-template:2.0.0.M3' under the dependencies in build.gradle(Module:app) and then the maven block:
maven {
url 'https://repo.spring.io/libs-milestone'
}
Is put in the allprojects set of braces below the dependencies block.

Related

Could not resolve com.android.support:appcompat-v7:28.0.0

There are many different questions about this, but the problems there are about using v7.28.0, v7.28.+, v7.28.0.0-rc02 But when I sync my project I get this error:
Unable to resolve dependency for ':app#debug/compileClasspath': Could
not resolve com.android.support:appcompat-v7:28.0.0.
I've checked Support library setup and followed it's instructions but it didn't help.
This is my module app
buildscript {
repositories {
maven { url 'https://plugins.gradle.org/m2/'}
}
dependencies {
classpath 'gradle.plugin.com.onesignal:onesignal-gradle-plugin:0.12.1'
}
}
apply plugin: 'com.onesignal.androidsdk.onesignal-gradle-plugin'
repositories {
maven { url 'https://maven.google.com' }
}
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
buildToolsVersion '28.0.3'
defaultConfig {
applicationId "com.mobaleghan.nasimnoor"
manifestPlaceholders = [
onesignal_app_id: 'b1ced87b-48d1-4857-a68b-9c287aa4003f',
// Project number pulled from dashboard, local value is ignored.
onesignal_google_project_number: 'REMOTE'
]
minSdkVersion 16
targetSdkVersion 28
versionCode 8
versionName "1.6.3"
vectorDrawables.useSupportLibrary = true
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'),
'proguard-rules.pro'
}
debug {
debuggable true
}
}
lintOptions {
abortOnError false
}
}
dependencies {
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:design:28.0.0'
implementation 'com.android.support:preference-v7:28.0.0'
implementation 'com.android.support:recyclerview-v7:28.0.0'
implementation 'com.android.support:support-annotations:27.1.1'
implementation 'com.android.support:support-v4:28.0.0'
implementation 'com.android.support:cardview-v7:28.0.0'
implementation 'com.google.android.apps.dashclock:dashclock-api:2.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.0'
implementation "com.android.support:support-core-utils:28.0.0"
implementation 'com.onesignal:OneSignal:3.10.3'
}
and project gradle:
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
The android studio internet connection is fine as I've tested in settings and I don't know where else to look.
I even created a new project in AS 3.2.1 But I get same error.
I don't know why this happens every time I update AS!
I'm sure other answers are good and working. but mine got solved by set proxy to Freedom of Developers.
This solution is for Persians like me who suffer from strict limitations for Iranians by google.
Now my app gradle look like this:
buildscript {
repositories {
maven { url 'https://plugins.gradle.org/m2/'}
}
dependencies {
classpath 'gradle.plugin.com.onesignal:onesignal-gradle-plugin:0.12.1'
}
}
apply plugin: 'com.onesignal.androidsdk.onesignal-gradle-plugin'
repositories {
maven { url 'https://maven.google.com' }
}
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
buildToolsVersion '28.0.3'
defaultConfig {
applicationId "com.mobaleghan.nasimnoor"
manifestPlaceholders = [
onesignal_app_id: 'b1ced87b-48d1-4857-a68b-9c287aa4003f',
// Project number pulled from dashboard, local value is ignored.
onesignal_google_project_number: 'REMOTE'
]
minSdkVersion 16
targetSdkVersion 28
versionCode 9
versionName "1.6.4"
vectorDrawables.useSupportLibrary = true
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'),
'proguard-rules.pro'
}
debug {
debuggable true
}
}
lintOptions {
abortOnError false
}
}
dependencies {
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:design:28.0.0'
implementation 'com.android.support:preference-v7:28.0.0'
implementation 'com.android.support:recyclerview-v7:28.0.0'
implementation 'com.android.support:support-annotations:28.0.0'
implementation 'com.android.support:support-v4:28.0.0'
implementation 'com.android.support:cardview-v7:28.0.0'
implementation 'com.google.android.apps.dashclock:dashclock-api:2.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation "com.android.support:support-core-utils:28.0.0"
implementation 'com.onesignal:OneSignal:3.10.3'
}
Those repositories are there based on OneSignal documentations.
And top level build:
buildscript {
repositories {
google()
jcenter()
maven {
url 'https://maven.google.com/'
name 'Google'
}
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
maven {
url 'https://maven.google.com/'
name 'Google'
}
}
}
And everything is working fine.
Android project has 2 gradle files: one stored in project scope and one stored in application scope. (noted that one project can have many applications inside, but you usually have one). So you only need to swap defined repository url in those 2 gradle files.
Step 1: Remove these lines of code in your build.gradle (app)
repositories {
maven { url 'https://maven.google.com' }
}
Step 2: Add this to your build.gradle (project)
allprojects {
repositories {
google()
jcenter()
maven { url 'https://maven.google.com' }
maven { url 'https://jitpack.io' }
mavenCentral()
}
}
One thing you have to aware that 28.0.0 is the last stable version of android.support. So you might want to downgrade version or migrate everything to androidX.
The stable release of 28.0.0 will be the final feature release packaged as android.support. All subsequent feature releases will only be made available as androidx-packaged artifacts.
Check out this link and welcome to the new era of androidX.
Try the following:
1) Uncheck offline work from build tools:
File -> Other Settings -> Default Settings -> Build, Execution, Deployment -> Build Tools->Gradle->Uncheck Offline work option.
2) If above doesn't work then go to your project's build gradle and add the following under repositories:
allprojects {
repositories {
jcenter()
maven {
url "https://maven.google.com"
}
}
}
merge this part from the module's build.gradle into the root project's build.gradle:
buildscript {
repositories {
maven { url 'https://plugins.gradle.org/m2/'}
}
dependencies {
classpath 'gradle.plugin.com.onesignal:onesignal-gradle-plugin:0.12.1'
}
}
repositories {
maven { url 'https://maven.google.com' }
}
only keep these lines in the module's build.gradle:
apply plugin: 'com.android.application'
apply plugin: 'com.onesignal.androidsdk.onesignal-gradle-plugin'
android {
...
}
the root project's build.gradle should look about like this then:
buildscript {
repositories {
google()
jcenter()
maven { url 'https://plugins.gradle.org/m2/' }
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
classpath 'gradle.plugin.com.onesignal:onesignal-gradle-plugin:0.12.1'
}
}
allprojects {
repositories {
google()
jcenter()
}
}
You can still use version 28.0.0 but it seems its time to migrate to Android X!
According to Support Library Documentation:
Note: With the release of Android 9.0 (API level 28) there is a new
version of the support library called AndroidX which is part of
Jetpack. The AndroidX library contains the existing support library
and also includes the latest Jetpack components.
You can continue to use the support library. Historical artifacts
(those versioned 27 and earlier, and packaged as android.support.*)
will remain available on Google Maven. However, all new library
development will occur in the AndroidX library.
We recommend using the AndroidX libraries in all new projects. You
should also consider migrating existing projects to AndroidX as well.

Setting up firebase on Android studio

I am trying to setup firebase on my android studio.I am using a 2.2.3 version.So this is my code in app.gradle file:
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
applicationId "com.example.parth.carpool"
minSdkVersion 22
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'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-a`enter code here`nnotations'
})
compile 'com.android.support:appcompat-v7:25.2.0'
compile 'com.google.firebase:firebase-core:16.0.1'
testCompile 'junit:junit:4.12'
}
apply plugin: 'com.google.gms.google-services'
This is the error that I am receiving.
Error:(27, 13) Failed to resolve: com.google.firebase:firebase-core:16.0.1
This is my project.gradle file:
// 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:2.2.3'
classpath 'com.google.gms:google-services:4.0.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
To correct this error I installed google play services, google repository, SDK platform,SDK platform tools etc. after I saw some of the posts on stackoverflow. Does anybody have a solution?
First you need to upgrade android studio to the newest version:
If you're not using Android Studio 3.1 to develop your app, you will need to upgrade in order to get the correct version checking behavior within the IDE.
https://android-developers.googleblog.com/2018/05/announcing-new-sdk-versioning.html
Then you need to use the following top level gradle file:
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.3'
classpath 'com.google.gms:google-services:4.0.1'
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Android Studio provides Awesome tool called Firebase Assistant, it handles any thing you need to setup firebase in you'r project
from Tools->Firebase
just pick which product you want and it'll do all the work for you
Make sure you are connected to a good network
Goto >file -> other settings -> Under build, execution, and deployment
-> you will see Gradle. uncheck the checkbox offline work. Then rebuild your project.
buildscript {
repositories {
// add google here
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.3'
classpath 'com.google.gms:google-services:4.0.0'
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Did you try on this link
In your root build.gradle file add the repo:
maven { url "https://maven.google.com" }
It depends upon you how you want to setup you can try both explicit way and implicit way of setting up firebase .the easiest one is implicit one which is given in android studio

Gradle build error: Failed to resolve:

I just downloaded Android Studio and created a new project and I'm getting gradle build errors:
Failed to resolve: com.android.support.test.espresso-core:2.2.2
and
Failed to resolve: com.android.support.appcompat-v7:25.3.1
This error was resolved reinstalling the SDK Tools + Repository + API when launching android studio as admin.
I've installed API Level 25 which what I want to build on and have downloaded the SDK Build-Tools. I have also already download the support repository
Here's my app file:
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion '25.0.3'
defaultConfig {
applicationId "com.jtsalas.mirrorcontrol"
minSdkVersion 25
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'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_6
targetCompatibility JavaVersion.VERSION_1_7
}
productFlavors {
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.3.1'
testCompile 'junit:junit:4.12'
}
build.gradle:
// 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:2.3.2'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
From the SDK manager, make sure you have both the Android Support Repository and Google Repository installed and up to date. You should then be able to find the relevant artifacts in sub folders of your /extras/android/m2repository directory
From your error it seems that you are not including espresso libraries. The solution to this is adding espresso core library which is part Android Testing support library which is hosted in the google's Maven repository think this as kind of git repository but for dependencies.
So we tell the gradle build system to look in the Maven repository for dependencies by specifying its URL.
This is done by adding Maven url in the application level build.gradle file under repositories block
repositories {
jcenter()
maven{
url "https://maven.google.com"
}
}
and in the module level build.gradle file mention the dependencies that you want from the maven repository by mention their name as follows:
dependencies{
//other dependencies go here
//testing dependencies
androidTestCompile 'com.android.support.test.espresso:espresso-core:3.0.1'
}
That is the reason for including Maven repository url in the app level build.gradle file, hope this helps.
In project.gradle file, the allprojects root align this way:
allprojects {
repositories {
google()
jcenter()
maven { url "https://jitpack.io" }
}
}
jitpack is used as the dependency for multiple libraries, if you're not using any sort of library that don't requires it then not include maven line.
Well, I don't know the perfect answer but..... how about comparing with my SDK Tools?
I solved it by uninstalling Android Studios and deleting old versions of Android Studios in my C:\Users[Username] and reinstalled Android Studio as administrator.
It seems like you updated android studio and opening previous project in it.The simplest way is create new project and copy
1. compileSdkVersion 26
2. buildToolsVersion "26.0.1"
3. targetSdkVersion 26
4. compile 'com.android.support:appcompat-v7:26.+'
and paste them in appropriate places in app level build gradle.
it will ask to update to take advantages .. allow it to update.
best luck ... It worked for me.
if your project is Flutter,
clean project [by 'flutter clean' command]
In project.gradle file add [ google() ]
in Android studio: File Menu -> Invalidate...
project.gradle:
allprojects {
repositories {
google()
jcenter()
}
}

Where can I put individual dependencies in Android Studio?

I am trying to install Picasso (http://square.github.io/picasso/) for use in Android Studio. One of the steps is to add this line: compile 'com.squareup.picasso:picasso:2.5.2' in build.gradle under dependencies. However, there is a message in gradle that tells me not to insert individual dependencies in the dependencies folder. What should I do?
// 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.3.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
You need to add it to the gradle.build file that is located in the "app" directory, not the one in your project directory. find the gradle.build file that sits within the "app" directory of your project.
Here is mine as an example:
apply plugin: 'com.android.application'
android {
compileSdkVersion 20
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "com.your.packagename"
minSdkVersion 15
targetSdkVersion 21
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
repositories { mavenCentral() }
dependencies {
compile 'com.android.support:appcompat-v7:18.0.+'
compile 'com.facebook.android:facebook-android-sdk:4.0.0'
compile 'com.parse.bolts:bolts-android:1.+'
compile 'com.parse:parse-android:1.+'
}
And a link to some supporting documentation:
http://developer.android.com/tools/building/configuring-gradle.html
Screenshot of the build.gradle(Module:app file)
Take a look at the image.
Do you see that there are actually 2 build.gradle files?
what you need is the (Module:app) gradle build file select that and paste the link in the dependencies part in the bottom of that file just like what i have done , then Android Studio will ask you to sync the file.
Do it.
It will download the dependency from your link provided and integrate with the project
Hope this helps..

Can't import project to android studio

I'm trying to use this library
I've added
compile 'net.rdrei.android.dirchooser:library:2.0#aar'
to dependecies.
My top level build file
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.8.+'
}
}
allprojects {
repositories {
mavenCentral()
}
}
And it gives me error "failed to refresh gradle project" with reference to the project, that I'm trying to import.
This library is not on Central Maven as aar.
Check here:
http://search.maven.org/#search%7Cga%7C1%7Cnet.rdrei.android.dirchooser
it is an apklib format.
I've checked the snapshots repo, and here you can find this library.
https://oss.sonatype.org/content/repositories/snapshots/net/rdrei/android/dirchooser/library/
To use the snap repo you have to change your script:
repositories {
mavenCentral()
maven {
url "https://oss.sonatype.org/content/repositories/snapshots"
}
}
Then add you depencency, for example
compile 'net.rdrei.android.dirchooser:library:2.1-SNAPSHOT'
The answer provided by #unify #GabrieleMariotti and #AndyJoiner is correct. However it confused be since we have two gradle files - a project level gradle and a inner gradle (where you write your dependencies). The solution is to add the code suggested by #AndyJoiner inside your inner gradle.
Since I was confused as to where to add the code, which took me an hour to figure out, I don't want it to happen to others. So, I am posting my both gradle files.
Project Level Gradle
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.0.0'
}
}
allprojects {
repositories {
jcenter()
}
}
Inner Gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "com.itcse.materialdesignsearchviewlikegoogleplay"
minSdkVersion 15
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
// Add the code for repositories here
repositories {
mavenCentral()
maven { url "https://oss.sonatype.org/content/repositories/snapshots" }
maven { url 'http://guardian.github.com/maven/repo-releases' }
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.3'
// Add the dependencies here
compile 'com.quinny898.library.persistentsearch:library:1.0.0-SNAPSHOT#aar'
}
Hope this help others in future.
This worked for me:
repositories {
maven { url 'https://oss.sonatype.org/content/repositories/snapshots' }
You can find the repository here
https://oss.sonatype.org/#nexus-search;quick~dirchooser
After trying the answer by Gabriele and a bit more digging, this worked for me
repositories {
mavenCentral()
maven { url "https://oss.sonatype.org/content/repositories/snapshots" }
maven { url 'http://guardian.github.com/maven/repo-releases' }
}
dependencies {
compile 'net.rdrei.android.dirchooser:library:2.2-SNAPSHOT#aar'
}

Categories

Resources