I'm trying to separate versions of the libraries to have all of them in one location in order to save time and complexity.
I saw a guy in some comment in some blog that sais the way he use to do this. He posted the next screens.
I can't use this way to construct the gradle, but I think that is a good way.
My Project build.gradle file:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
maven {
url "https://maven.google.com"
}
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
maven {
url "https://maven.google.com"
}
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
// Definition of versions of libraries
ext {
toolVersions = [
android :[
versionCode : 1,
versionName : "0.0.1",
minSdk : 16,
targetSdk : 26,
compileSdk : 26,
buildTools : "26.0.2",
support : "26.1.0"
],
espressoCore : "2.2.2",
junit : "4.12"
]
libVersions = [
glide : "4.2.0",
flubber : "1.0.1"
]
}
My app build.gradle file:
apply plugin: 'com.android.application'
android {
compileSdkVersion toolVersions.android.compileSdk
buildToolsVersion toolVersions.android.buildTools
defaultConfig {
applicationId "com.maol.brastlewark"
minSdkVersion toolVersions.android.minSdk
targetSdkVersion toolVersions.android.targetSdk
versionCode toolVersions.android.versionCode
versionName toolVersions.android.versionName
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:' + toolVersion.espressoCore, {
exclude group: 'com.android.support', module: 'support-annotations'
})
// SUPPORT LIBRARIES
compile 'com.android.support:appcompat-v7:' toolVersion.support
compile "com.android.support:support-core-utils:$rootProject.toolVersion.support"
testCompile "junit:junit:$rootProject.toolVersion.junit"
// IMAGE LOADER LIBRARY
compile "com.github.bumptech.glide:glide:$rootProject.libVersions.glide"
annotationProcessor "com.github.bumptech.glide:compiler:$rootProject.libVersions.glide"
// VIEW ANIMATIONS
compile "com.appolica:flubber:$rootProject.libVersions.flubber"
}
I don't know how to used this in the build.gradle (app). Anyone in the room can advised me something?
Thank you
You can create a file (for example gradleScript/dependencies.gradle):
ext {
//Version
supportLibrary = '26.1.0'
//Support Libraries dependencies
supportDependencies = [
design : "com.android.support:design:${supportLibrary}",
recyclerView : "com.android.support:recyclerview-v7:${supportLibrary}",
cardView : "com.android.support:cardview-v7:${supportLibrary}",
appCompat : "com.android.support:appcompat-v7:${supportLibrary}",
supportAnnotation: "com.android.support:support-annotations:${supportLibrary}",
]
}
In the top level file build.gradle add:
// Load dependencies
apply from: 'gradleScript/dependencies.gradle'
In the module1/build.gradle:
// Module build file
dependencies {
//......
compile supportDependencies.appCompat
compile supportDependencies.design
}
Solution that preserves lint update checks
You can use the same construct as in your question. To preserve the lint update checks you'd only include the version number (rather than the entire dependency name).
Create an ext block in your project level build.gradle file
Each item in the ext block acts like a map so we can organize dependency versions in an array.
ext {
playServicesVersions = [
base : '17.6.0',
location: '18.0.0',
maps : '17.0.0'
]
supportVersions = [
nameHere: '3.0.0'
]
}
Access dependency versions
Note that curly braces are used here because more than one variable is accessed.
dependencies {
implementation "com.google.android.gms:play-services-base:${playServicesVersions.base}"
implementation "com.google.android.gms:play-services-location:${playServicesVersions.location}"
implementation "com.google.android.gms:play-services-maps:${playServicesVersions.maps}"
}
Lint checks still active
To make that possible you can declare ext{} block in your build.gradle file.
ext {
def AAVersion = '4.0-SNAPSHOT' // change this to your desired version
}
dependencies {
apt "org.androidannotations:androidannotations:$AAVersion"
compile "org.androidannotations:androidannotations-api:$AAVersion"
}
If you want to work with arrays:
ext {
supportDependencies = [
design : "com.android.support:design:${supportLibrary}",
// whatever lib...
]
}
then when you want to call it:
dependencies {
compile supportDependencies.design
}
You can declare the dependencies in your settings.gradle:
dependencyResolutionManagement {
versionCatalogs {
libs {
alias('protobuf').to('com.google.protobuf:protobuf-java:3.15.8')
alias('snappy').to('org.xerial.snappy:snappy-java:1.1.8.4')
alias('junit').to('junit:junit:4.13.2')
}
}
}
And then use them in build.gradle:
dependencies {
api libs.protobuf
api libs.snappy
testImplementation libs.junit
}
It works for multi-project builds as well.
Please refer to official docs for details.
Related
I'm receiving both errors:
Could not create task ':processDebugGoogleServices'.
Cannot create a proxy class for abstract class 'GoogleServicesTask'.
// GENERATED BY UNITY. REMOVE THIS COMMENT TO PREVENT OVERWRITING WHEN EXPORTING AGAIN
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.4.0'
classpath 'com.google.gms:google-services:4.3.4'
**BUILD_SCRIPT_DEPS**}
}
allprojects {
repositories {
google()
jcenter()
flatDir {
dirs 'libs'
}
}
}
// Android Resolver Repos Start
([rootProject] + (rootProject.subprojects as List)).each {
ext {
it.setProperty("android.useAndroidX", true)
it.setProperty("android.enableJetifier", true)
}
}
([rootProject] + (rootProject.subprojects as List)).each { project ->
project.repositories {
def unityProjectPath = $/file:///**DIR_UNITYPROJECT**/$.replace("\\", "/")
maven {
url "https://maven.google.com"
}
maven {
url "https://deltadna.bintray.com/android" // Assets/DeltaDNA/Editor/Android/Dependencies.xml:8
}
maven {
url (unityProjectPath + "/Assets/GeneratedLocalRepo/Firebase/m2repository") // Assets/Firebase/Editor/AnalyticsDependencies.xml:18, Assets/Firebase/Editor/AppDependencies.xml:22
}
mavenLocal()
jcenter()
mavenCentral()
}
}
// Android Resolver Repos End
apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
**APPLY_PLUGINS**
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
// Android Resolver Dependencies Start
implementation 'com.android.support:appcompat-v7:25.3.1' // Facebook.Unity.Editor.AndroidSupportLibraryResolver.addSupportLibraryDependency
implementation 'com.android.support:cardview-v7:25.3.1' // Facebook.Unity.Editor.AndroidSupportLibraryResolver.addSupportLibraryDependency
implementation 'com.android.support:customtabs:25.3.1' // Facebook.Unity.Editor.AndroidSupportLibraryResolver.addSupportLibraryDependency
implementation 'com.android.support:support-v4:25.3.1' // Facebook.Unity.Editor.AndroidSupportLibraryResolver.addSupportLibraryDependency
implementation 'com.deltadna.android:deltadna-sdk-notifications:4.10.0' // Assets/DeltaDNA/Editor/Android/Dependencies.xml:8
implementation ('com.facebook.android:facebook-applinks:[5,6)') {
exclude group: 'com.google.zxing'
}// Assets/FacebookSDK/Plugins/Editor/Dependencies.xml:6
implementation ('com.facebook.android:facebook-core:[5,6)') {
exclude group: 'com.google.zxing'
}// Assets/FacebookSDK/Plugins/Editor/Dependencies.xml:5
implementation ('com.facebook.android:facebook-login:[5,6)') {
exclude group: 'com.google.zxing'
} // Assets/FacebookSDK/Plugins/Editor/Dependencies.xml:7
implementation ('com.facebook.android:facebook-share:[5,6)') {
exclude group: 'com.google.zxing'
} // Assets/FacebookSDK/Plugins/Editor/Dependencies.xml:8
implementation 'com.google.android.gms:play-services-base:17.4.0' // Assets/Firebase/Editor/AppDependencies.xml:17
implementation 'com.google.firebase:firebase-analytics:17.6.0' // Assets/Firebase/Editor/AppDependencies.xml:15
implementation 'com.google.firebase:firebase-analytics-unity:6.16.0' // Assets/Firebase/Editor/AnalyticsDependencies.xml:18
implementation 'com.google.firebase:firebase-app-unity:6.16.0' // Assets/Firebase/Editor/AppDependencies.xml:22
implementation 'com.google.firebase:firebase-common:19.3.1' // Assets/Firebase/Editor/AppDependencies.xml:13
implementation 'com.parse.bolts:bolts-android:1.4.0' // Assets/FacebookSDK/Plugins/Editor/Dependencies.xml:4
// Android Resolver Dependencies End
// ** revenuecat **
implementation ('com.revenuecat.purchases:purchases-hybrid-common:1.2.0') {
exclude group: 'com.android.billingclient', module: 'billing'
}
implementation 'com.android.support:multidex:1.0.3'
**DEPS**}
// Android Resolver Exclusions Start
android {
packagingOptions {
exclude ('/lib/armeabi/*' + '*')
exclude ('/lib/mips/*' + '*')
exclude ('/lib/mips64/*' + '*')
exclude ('/lib/x86/*' + '*')
exclude ('/lib/x86_64/*' + '*')
}
}
// Android Resolver Exclusions End
android {
compileSdkVersion **APIVERSION**
buildToolsVersion '**BUILDTOOLS**'
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
defaultConfig {
minSdkVersion **MINSDKVERSION**
targetSdkVersion **TARGETSDKVERSION**
multiDexEnabled true
applicationId '**APPLICATIONID**'
ndk {
abiFilters **ABIFILTERS**
}
versionCode **VERSIONCODE**
versionName '**VERSIONNAME**'
}
lintOptions {
abortOnError false
}
aaptOptions {
noCompress = ['.unity3d', '.ress', '.resource', '.obb'**STREAMING_ASSETS**]
ignoreAssetsPattern = "!.svn:!.git:!.ds_store:!*.scc:.*:!CVS:!thumbs.db:!picasa.ini:!*~"
}**SIGN**
buildTypes {
debug {
minifyEnabled **MINIFY_DEBUG**
useProguard **PROGUARD_DEBUG**
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-unity.txt'**USER_PROGUARD****SIGNCONFIG**
jniDebuggable true
}
release {
minifyEnabled **MINIFY_RELEASE**
useProguard **PROGUARD_RELEASE**
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-unity.txt'**USER_PROGUARD****SIGNCONFIG**
}
}**PACKAGING_OPTIONS****SPLITS**
**BUILT_APK_LOCATION**
**EXTERNAL_SOURCES**
bundle {
language {
enableSplit = false
}
density {
enableSplit = false
}
abi {
enableSplit = true
}
}
}**SPLITS_VERSION_CODE****REPOSITORIES****SOURCE_BUILD_SETUP**
I saw several threads that said i should remove apply plugin: 'com.google.gms.google-services'
or to update classpath 'com.android.tools.build:gradle:3.4.0' to classpath 'com.android.tools.build:gradle:4.0.0' but that didn't do it for me and only caused more problems.
Also running ./gradlew :dependencies didn't show anything.
It's difficult to exactly say what's happening, but I have a few suggestions that should work.
First, get rid of classpath 'com.google.gms:google-services:4.3.4' under dependencies and apply plugin: 'com.google.gms.google-services'. The reason is that the purpose of this is to read a google-services.json file in your project directory and generate a res/values/google-services.xml file (more information here). The Firebase SDK for Unity will do this automatically placing this file under Assets/Plugins/FirebaseApp.androidlib/res/values/google-services.xml. Anything in a Plugins/*.androidlib file is now automatically pulled into the Android project, rendering this step redundant (and often causing errors both on the Unity and Android side).
Since you've used Unity to generate a mainTemplate.gradle file and you're using a newer version of Unity (2019.3 and above), you'll also need to generate a gradleTemplate.properties file. This way we can enable AndroidX (the replacement for the Android Support libraries now used by Firebase) and enable Jetifier (which will upgrade Google Support dependencies that it looks like Facebook is pulling in).
From here, since you mentioned disabling the External Dependency Manager for Unity (EDM4U), you will want to force resolve your Android dependencies.
You will want to have "Patch mainTemplate.gradle", "Use Jetifier.", and "Patch gradleTemplate.properties" all checked in your Android Resolver Settings for this to work:
If you're running into issues or you don't want to run EDM4U, I'm trying to do is add android.useAndroidX=true and android.enableJetifier=true to gradleTemplate.properties. For my own game, this file now looks like:
org.gradle.jvmargs=-Xmx**JVM_HEAP_SIZE**M
org.gradle.parallel=true
android.enableR8=**MINIFY_WITH_R_EIGHT**
**ADDITIONAL_PROPERTIES**
android.useAndroidX=true
android.enableJetifier=true
To recap, at this point you should have removed the play services plugin and enabled AndroidX and Jetifier support. You should be able to either build from Unity or export a gradle project and build from the command line (this latter is always a challenge in Unity since they opt to not use gradlew, so you may run into incompatibility with your system gradle).
If this doesn't help, I'd like to see a more complete error log to try to suss out the actual cause.
In your root-level (project-level) Gradle file (build.gradle), add rules to include the Google Services Gradle plugin. Check that you have Google's Maven repository, as well.
dependencies {
classpath 'com.google.gms:google-services:3.0.0'
classpath 'com.android.tools.build:gradle:3.3.1'
}
And then:
In your module (app-level) Gradle file (usually app/build.gradle), apply the Google Services Gradle plugin:
apply plugin: 'com.google.gms.google-services'
I had issue with combo Firebase+Unity+gradle. Solved by downgrading gradle.
Unity -> Edit -> Preference -> Gradle to version 6.7.1
It seems that Firebase could not work with newer gradle versions.
Download: Gradle
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.
Hare is my app gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
defaultConfig {
applicationId "com.example.atumanin.testandroidannotations"
minSdkVersion 15
targetSdkVersion 26
versionCode 1
versionName "1.1.18"
javaCompileOptions {
annotationProcessorOptions {
includeCompileClasspath true
}
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'io.reactivex.rxjava2:rxjava:2.1.6'
implementation 'io.reactivex.rxjava2:rxandroid:2.0.1'
}
and this is my project gradle:
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.0'
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
If I try to build project, I get error:
Could not resolve io.reactivex.rxjava2:rxjava:2.1.6.
and
Could not resolve io.reactivex.rxjava2:rxandroid:2.0.1.
I tried to clean, to rebuild the project and to invalidate cache. Nothing helps. I also tried to use compile instead of implementation. I also tried different versions of both libraries, also without success.
It will give error because official release for rxjava is 2.1.5.
simply change below lines of code
implementation 'io.reactivex.rxjava2:rxandroid:2.0.1'
implementation 'io.reactivex.rxjava2:rxjava:2.1.5'
Official documentation
I found the solution. The issue was my proxy, it blocks https and I need to use the http version of repository. So instead of:
repositories {
jcenter()
}
I use now:
repositories {
jcenter {
url "http://jcenter.bintray.com/"
}
}
and it compiles now.
Changing
implementation 'io.reactivex.rxjava2:rxjava:2.1.6'
implementation 'io.reactivex.rxjava2:rxandroid:2.0.1'
to
api 'io.reactivex.rxjava2:rxjava:2.x.x'
api 'io.reactivex.rxjava2:rxandroid:2.0.1'
worked for me
#link https://github.com/ReactiveX/RxAndroid
// Because RxAndroid releases are few and far between, it is recommended you also
// explicitly depend on RxJava's latest version for bug fixes and new features.
// (see https://github.com/ReactiveX/RxJava/releases for latest 3.x.x version)
// Step 1 : in side build.gradle(Module:app)
implementation 'io.reactivex.rxjava2:rxandroid:2.0.1'
// Step 2 : in side build.gradel(Project:ProjectName)
allprojects {
repositories {
google()
jcenter()
maven { url "https://jitpack.io" }
jcenter {
url "http://jcenter.bintray.com/"
}
}
}
Just try to uncheck the offline mode in your
Settings -> Gradle
and try again.That's worked for me
I imported the sample app in Android Studio under the location section. I then proceeded to update most of the dependancies. I then attempted to add Firebase and that's when things went south. The module build.gradle is below.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.2'
}
}
apply plugin: 'com.android.application'
repositories {
jcenter()
}
dependencies {
compile 'com.google.android.gms:play-services-location:10.0.1'
compile 'com.google.android.gms:play-services-maps:10.0.1'
compile 'com.github.bumptech.glide:glide:3.6.1'
compile 'com.google.maps.android:android-maps-utils:0.4.4'
compile 'com.android.support:appcompat-v7:25.0.1'
compile 'com.android.support:recyclerview-v7:25.0.1'
compile 'com.android.support:design:25.0.1'
compile 'com.google.android.gms:play-services-wearable:10.0.1'
compile 'com.android.support:support-v13:25.0.1'
compile project(':Shared')
wearApp project(':Wearable')
}
// The sample build uses multiple directories to
// keep boilerplate and common code separate from
// the main sample code.
List<String> dirs = [
'main', // main sample code; look here for the interesting stuff.
'common', // components that are reused by multiple samples
'template'] // boilerplate code that is generated by the sample template process
android {
compileSdkVersion 25
buildToolsVersion '24.0.2'
defaultConfig {
minSdkVersion 18
targetSdkVersion 25
versionCode 1
versionName "1.0"
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
sourceSets {
main {
dirs.each { dir ->
java.srcDirs "src/${dir}/java"
res.srcDirs "src/${dir}/res"
}
}
androidTest.setRoot('tests')
androidTest.java.srcDirs = ['tests/src']
}
productFlavors {
}
}
apply plugin: 'com.google.gms.google-services'
The root build.gradle is below.
buildscript {
// ...
dependencies {
// ...
classpath 'com.google.gms:google-services:3.0.0'
}
}
And the error I receive is :
Error:Could not find com.google.gms:google-services:3.0.0.
Searched in the following locations:
file:/C:/Android/Android Studio/gradle/m2repository/com/google/gms/google-services/3.0.0/google-services-3.0.0.pom
file:/C:/Android/Android Studio/gradle/m2repository/com/google/gms/google-services/3.0.0/google-services-3.0.0.jar
Required by:
:ToledoZoo:unspecified
Using the latest SDK, and all. Added the google.json file to the app directory as well. I am sure it is something small I am missing, but yet... still missing it!
The module build.gradle is below
app/ is a module, and the buildscript block should not be within that.
The app build.gradle is below.
If by this, you mean build.gradle in the root of the project, then it is that file where you add the classpath of the play services.
Refer. https://firebase.google.com/docs/android/setup#add_the_sdk
Note, when the documentation says
buildscript {
// ...
dependencies {
// ...
classpath 'com.google.gms:google-services:3.0.0'
}
You do not literally copy the // ... pieces. It means "leave what is there already".
If you have a single module Gradle project, then that might make sense looking at your question, and so you need to have
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.2'
classpath 'com.google.gms:google-services:3.0.0'
}
}
apply plugin: 'com.android.application'
// rest of gradle file
I'm not a Gradle expert. That said, the layout of your build.gradle files is unconventional. Typically, in the module file, the dependencies block is after the android block. Examples of build files are in the Firebase sample project. Take a look at this sample project build file and this sample module build file.
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.