When I import projects from github into Android studio I see various errors related to the gradle version. For all the miseries of Eclipse I dont ever remember needing to do an upgrade every time to all sorts of different reasons. Usually it was SDK only.
I see a lot of errors along the lines of:
Error:failed to find Build Tools revision 21.1.0
Install Build Tools 21.1.0 and sync project
Failed to apply plugin [id 'com.android.application'] Gradle version 2.1 is required. Current version is 2.2.1. If using the gradlewrapper, try editing the distributionUrl in /Users/Mac1/Downloads/u2020-dagger2 /gradle/wrapper/gradle-wrapper.properties to gradle-2.1-all.zip
It seems odd that a system designed to reduce the complexity of dependencies would demand the installation of old versions of gradle or build tools. Why does this kind of thing happen. Does this mean it has no build tools or just not that version? Does it mean it must be the old version? It certainly seems to be encouraging backward compatibility by insisting in installing old versions of everything. Gradle, build tools etc. I don't mean to be rude, so I'll keep quiet about what I think of this. In the meantime, what are we supposed to do?
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.14.1'
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.4'
}
}
allprojects {
repositories {
mavenCentral()
maven {
url 'https://oss.sonatype.org/content/repositories/snapshots/'
}
}
}
Here is project level build.gradle:
apply plugin: 'com.android.application'
apply plugin: 'com.neenbedankt.android-apt'
android {
compileSdkVersion 21
buildToolsVersion '21.1.0'
defaultConfig {
applicationId 'dagger.demo'
minSdkVersion 15
targetSdkVersion 21
versionCode 1
versionName '1.0'
}
}
dependencies {
compile 'com.google.dagger:dagger:2.0-SNAPSHOT'
apt 'com.google.dagger:dagger-compiler:2.0-SNAPSHOT'
provided 'org.glassfish:javax.annotation:10.0-b28'
}
First, make sure you have the latest Gradle version or atleast 2.2.1. Then update your build.gradle:
Top build.gradle:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.1.3' // <-- updated
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.4'
}
}
allprojects {
repositories {
mavenCentral()
maven {
url 'https://oss.sonatype.org/content/repositories/snapshots/'
}
}
}
App build.gradle:
apply plugin: 'com.android.application'
apply plugin: 'com.neenbedankt.android-apt'
android {
compileSdkVersion 22
buildToolsVersion '21.0.0'
defaultConfig {
applicationId 'dagger.demo'
minSdkVersion 15
targetSdkVersion 22
versionCode 1
versionName '1.0'
}
}
dependencies {
compile 'com.google.dagger:dagger:2.0-SNAPSHOT'
apt 'com.google.dagger:dagger-compiler:2.0-SNAPSHOT'
provided 'org.glassfish:javax.annotation:10.0-b28'
}
Related
I'm getting "Error: buildToolsVersion is not specified"
I've seen many people get this error but it has either been due to buildtooslversion not being specified in the module build.gradle or apply plugin being in the top level.
Top level build.gradle
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.0'
classpath 'com.google.gms:google-services:3.0.0'
}
}
allprojects {
repositories {
jcenter()
}
}
dependencies {
}
Module build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
buildToolsVersion "28.0.2"
defaultConfig {
applicationId "com.tst.test_app"
minSdkVersion 9
targetSdkVersion 28
}
}
dependencies {
compile project(':test_app_lib')
compile 'com.google.android.gms:play-services-ads:9.6.1'
compile 'com.firebase:firebase-client-android:2.3.1'
compile 'com.google.firebase:firebase-core:9.6.0'
}
apply plugin: 'com.google.gms.google-services'
It's been a year since I touched this code. I previously built ok. I updated android studio and SDKs and switch to target SDK28. That's pretty much all I changed.
add google() above jcenter() inside
repositories {
google()
jcenter()
}
You don't need to say which build tools are you using when you are using Android Pie
You only need to have something like this:
compileSdkVersion 28
defaultConfig {
applicationId "your.app"
minSdkVersion 18
targetSdkVersion 28
versionCode 0
versionName "1.0"
}
And please update your dependencies from compile to implementation, like this:
implementation 'com.google.firebase:firebase-core:16.0.3'
If your minSdkVersion is currently below 14, you will need to set it to 14 or higher. This is a limitation introduced in 26.
It ended up that buildToolsVersion was not specified in the LIBRARY (test_app_lib). When I added that, the error went away
I want to add to my app some ads using AdMob, the site says I need to add Google Services to the dependencies to use this functionality. So with Android Studio I went to File->Project Structure->app->Dependencies, I clicked on the "+" button e searched for "play-services". What I found was "com.google.android.gms:play-services:9.4.0" so I added it to the dependencies. During the gradle sync however Android Studio sends some errors and stops the gradle sync.
This is the log I get form the sync: http://pastebin.com/ZpN4RUcm
Here some data that might be useful:
Compile SDK Version: API 17
Build Tools Version: 23.0.1
Android
Studio 2.1.2
This is my main gradle file:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
dependencies {
classpath 'com.android.tools.build:gradle:2.1.2'
}
}
allprojects {
repositories {
jcenter()
}
}
And this is my app gradle file:
apply plugin: 'com.android.application'
android {
compileSdkVersion 'Google Inc.:Google APIs:17'
buildToolsVersion '23.0.1'
defaultConfig {
applicationId "com.serpenssolida.glowdodger"
minSdkVersion 10
targetSdkVersion 17
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
repositories {
mavenCentral()
}
dependencies {
compile 'com.android.support:support-v4:17.0.0'
compile files('libs/processing-core.jar')
compile project(':facebook')
compile 'com.google.android.gms:play-services:9.4.0'
}
How can I get rid of all the errors?
Change your app gradle file as below and try again:
apply plugin: 'com.android.application'
android {
compileSdkVersion '24'
buildToolsVersion '24.0.2'
...
}
I am completely new to realm. I want to use realm db in my android project. I have gone through the official Realm documentation. I need to set up realm in my android project. For that I have added the gradle dependancy as
buildscript {
repositories {
jcenter()
}
dependencies {
classpath "io.realm:realm-gradle-plugin:0.88.2"
}
}
apply plugin: 'realm-android'
This is what they have given in documentation. But this doesn't work for me. It gives error saying Plugin with id 'realm-android' not found.
This is my build.gradle file
apply plugin: 'com.android.application'
apply plugin: 'realm-android'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "com.db.realmsample"
minSdkVersion 14
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
buildscript {
repositories {
jcenter()
}
dependencies {
classpath "io.realm:realm-gradle-plugin:0.88.2"
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.2.1'
}
Is my configuration correct?
Move the buildscript to your main build.gradle file (Project) , it shouldn't be there in build.gradle (module:app)
buildscript {
repositories {
jcenter()
}
dependencies {
classpath "io.realm:realm-gradle-plugin:<realm version>"
}
}
This should go to main build.gradle
First of all copy the class path dependency to build.gradle file(Project):-
buildscript {
repositories {
jcenter()
}
dependencies {
classpath "io.realm:realm-gradle-plugin:1.2.0"
}
}
Finally, copy and paste the following code on top of build.gradle(App) :-
apply plugin: 'realm-android'
Note:- The version 1.2.0 is subjected to change on future releases.For more please check https://realm.io/docs/java/latest/
Prerequisites
Android Studio version 1.5.1 or higher
JDK version 7.0 or higher
A recent version of the Android SDK
Android API Level 9 or higher (Android 2.3 and above)
Step 1: Add the class path dependency to the project level build.gradle file.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath "io.realm:realm-gradle-plugin:4.1.1"
}
}
Step 2: Apply the realm-android plugin to the top of the application level build.gradle file.
apply plugin: 'realm-android'
Step 3: Gradle sync
For the official complete installation guide. Please see the following link.
https://realm.io/docs/java/latest/#installation
The method I used is
` dependencies
{
classpath 'com.android.tools.build:gradle:3.0.0'
classpath "io.realm:realm-gradle-plugin:3.1.4"
}`
in your main build gradle file
then add
apply plugin: 'realm-android'
and
compile 'io.realm:android-adapters:2.0.0'
in your app's build gradle
this link to bintray will give you the latest build
https://bintray.com/realm/maven/realm-android-library/3.4.0#files/io%2Frealm%2Frealm-android-library%2F3.4.0
I've referenced roboguice 2.0 in my new Android project build with Android Studio, here is my build.gradle file:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.4.2'
}
}
apply plugin: 'android-library'
repositories {
mavenCentral()
}
dependencies {
compile files('/libs/android-support-v4.jar')
compile 'org.roboguice:roboguice:2.0'
}
android {
compileSdkVersion 17
buildToolsVersion "17.0.0"
defaultConfig {
minSdkVersion 10
targetSdkVersion 16
}
}
Both gradle clean and gradle build run successfully but the IDE is reporting the error Element resources must be declared in roboguice.xml
Am I missing something or is this a bug in the IDE?
Mystery solved,
I've accidentally copied roboguice.xml to res/menu instead of res/values
I am having some problems with Android Studio 0.1.5.
My app compiles and runs on my device.
But the java source code is full of red errors with
Cannot resolve Symbol
This only seems to happen with components that are in libs (ex Roboguice)
Here is my build.gradle (though the problem looks more on Android Studio)
build.gradle
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.4.2'
}
}
apply plugin: 'android'
dependencies {
compile files(
'libs/GoogleAdMobAdsSdk-6.3.1.jar',
'libs/gson-2.2.2.jar',
'libs/guice-3.0-no_aop.jar',
'libs/javax.inject-1.jar',
'libs/roboguice-2.0b4.jar',
'libs/roboguice-sherlock-1.0.jar',
)
compile project(':libraries:ActionBarSherlock')
compile project(':libraries:android-ColorPickerPreference')
}
android {
compileSdkVersion 17
buildToolsVersion "17.0.0"
defaultConfig {
minSdkVersion 7
targetSdkVersion 16
}
}
Do you have any hints?
Thanks.
I solved by selecting those libraries and then added as library.