How to solve Android Studio Error With gradle - java

apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.03.1"
defaultConfig {
applicationId "com.example.admin.myapplication"
minSdkVersion 14
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', includes: ['*.jar'])
mobileApp project (':mobile')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:25.03.1'
compile 'com.google.android.gms:play-services'
I seen some stack on stack overflow But Still My error is Not Solved I try to understand previous Stack on Stack over flow but it's not working I post on some group no buddy reply so I post here.

By looking at your comments on StackOverflow I guess this is the real culprit,
buildToolsVersion "25.03.1"
and
compile 'com.android.support:appcompat-v7:25.03.1'
Change it to
buildToolsVersion "25.3.1" // remove 0 before 3
compile 'com.android.support:appcompat-v7:25.3.1' // remove 0 before 3
And rebuild the project.
Edit
In order to fix the below error
Wed Sep 13 04:59:29 IST 2017 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists distributionUrl=https://services.gradle.org/distributions/g‌​radle-3.3-all.zip the buidl file may missing agradle plugin
Download Gradle from their official site, currently it is 4.1 and extract it to somewhere in your system. (Ex. C:/gradle-4.1/)
Now in Android Studio goto File - Settings - Build and Execution - select Gradle
Here, by default it is Default gradle wrapper(recommended). Now select 2nd radio button and browse to your extracted gradle folder/drive (in my case C:/gradle-4.1). Click OK. (If you want offline mode you can select)
After that click Apply - OK. Now Android Studio starts building project. This will resolve your problem.

Related

Gradle Project Sync Failed Android Studio 3.0 (JDK 9.0.1)

I tried all solutions to fix it, but nothing has succeeded. (Turned gradle to "offline work", deleted .gradle files, invalidated and restarted. I also removed the jdk-android studio completely and installed again.)
Here is the problem's screenshot:
Android Studio 3.0 Gradle Sync Problem
Here is my java version
and here is the system/log file:
I think add build tools and sdk version 23 or 24
and if you select to use 23 build tools and sdk version, add dependency like this
compile 'com.android.support:appcompat-v7:23.1.1'
Note:
Wherever its written 26, replace with 23, only if you choose to 23 build tools and sdk version
If there is still any problem you can ask.
You can open build.gradle file in Android studio, then change compileSdkVersion , buildToolsVersion dependencies like this
android {
compileSdkVersion 23
buildToolsVersion "24.0.1"
....
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
}
If you did not understood it, can you please share screen shots of your build.gradle file ?
Which is in left side of android studio, under Gradle Scripts -> build.gradle (Modual:app)
Do it this way
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
defaultConfig {
applicationId "com.example.hackl.happybirthday"
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.0"
testInstrumentationRunner
"android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:23.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
testCompile 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'}
and click sync now (it will be automatically appear when you make changes in this file)
Take these easy steps as per developer.android.com
first add these lines on build.gradle file
buildscript {
repositories {
jcenter()
// You need to add the following repository to download the
// new plugin.
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.0'
}
}
after that
update Gradle manually, edit the URL in gradle-wrapper.properties to the following:
distributionUrl=\
https\://services.gradle.org/distributions/gradle-4.1-all.zip
For your reference you can check the below link
https://developer.android.com/studio/build/gradle-plugin-3-0-0-migration.html
I uninstalled Android Studio completely and reinstall 3 times. In every step I clicked on Gradle Sync error messages and installed all missing files. 3rd time installation has succeeded with get rid of gradle sync problem with installing missing files correctly. I don't know how and why it has not been successful 1st and 2nd time installation. Anyway, it's done.
Note: Before that I have tried all of answers. Thanks a lot.
Succeeded

Android Studio: Failed to resolve: com.google.android.gms:play-services:fp9.0.0

When I try to compile I get this error
"Failed to resolve: com.google.android.gms:play-services:fp9.0.0" in Android Studio. I am trying to include the play services in my project. This is my build.gradle file:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
defaultConfig {
applicationId "Application name"
minSdkVersion 21
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.3.0'
compile 'com.google.android.gms:play-services:fp9.0.0'
}
The only thing I have changed in this file is this line:
compile 'com.google.android.gms:play-services:fp9.0.0'
I have installed Google Play Services and it's version number is 30.
I had the same issue yesterday. In the messages section when running a gradle sync or build, I got a message with an option to update something from the M2 repo. Clicking the link downloaded the latest version and fixed the issue.
You could also try compile 'com.google.android.gms:play-services:9.0.0'
If you are only using maps, consider only downloading maps using compile 'com.google.android.gms:play-services-maps:9.0.0' as it can save you hitting the 65K method dex limit later in development.
Try to add and change this in your Project Level Gradle.
Update classpath com.google.gms:google-services:2.1.0 to classpath com.google.gms:google-services:3.0.0
And
Also try to change compile Dependencies as below.
compile 'com.google.android.gms:play-services:9.0.0'
Or for map you can only use this.
compile 'com.google.android.gms:play-services-maps:9.0.0'

Android Studio package in external jar cannot be resolved

I want to create an android app and I need an external SDK which I added to my project according to this answer: https://stackoverflow.com/a/30726911/4276486
In the picture below you can see that the packages in the external .jar cannot be resolved. However, when I am typing the IDE does autocomplete the package names but complains afterwards that the package cannot be resolved.
Any ideas how to fix this issue?
My gradle build file:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "dhbw.naorobotapp"
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 project(':java-naoqi-sdk-2.1.4.13-win32-vs2010')
}
Add this in your app gradle under dependencies, after you paste the .jar file under /libs
compile files('libs/<your jar filename>.jar')

can not resolve the symbol AppcomapatActivity

I am just starting to learn android and i just installed android studio on windows 10 pc. And the very first problem that I am facing is "can not resolve the symbol "AppCompatActivity". Here is my gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "quikkhome.com.myapplication"
minSdkVersion 14
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.0'
compile 'com.android.support:design:23.1.0'
compile 'com.android.support:appcompat-v7:23.1.0'
}
there is problem
android {
compileSdkVersion 23
buildToolsVersion '23.0.1'
you are added 2 time
compile 'com.android.support:appcompat-v7:23.1.0'
remove one time may be its help you
I just fixed the problem (though I do not know how did it work). I just changed the API from 21 to 23 and then back to 21. It is working perfectly now.
Try looking at your xml layout files, make sure all are targeting the same API. Change them to what ever you are targeting if different, like API 23 for example. The latest API may not be working yet, like N preview for example. This can be done by clicking the 'design' tab at the bottom if you are looking at an xml layout. Look for the little android man with the number beside it, click it.
Now also make sure the same theme is selected for all layout files. For example you may be using AppTheme as the theme.
Last run 'clean project'. At the top click Build, in the drop down menu click Clean Project.

android studio build suddenly throws a lot of errors

I have been developing this android for some days now, and suddenly the application build has a lot of errors and doesn't run. First few errors are listed below
D:\somepath\someotherpath\app\build\intermediates\exploded-aar\com.android.support\appcompat-v7\21.0.3\res\values-v11\values.xml
Error:(50, 21) No resource found that matches the given name: attr 'android:actionModeShareDrawable'.
Error:(50, 21) No resource found that matches the given name: attr 'android:actionModeShareDrawable'.
Error:(50, 21) No resource found that matches the given name: attr 'android:actionModeShareDrawable'.
Error:(50, 21) No resource found that matches the given name: attr 'android:actionModeShareDrawable'.
A couple of things might have caused these errrors are listed below
I was attempting to speed up the Emulator by using Intel HAXM, and also use Genymotion. I can see changes in the dependencies of the build.gradle
build.gradle old
apply plugin: 'com.android.application'
android {
compileSdkVersion 20
buildToolsVersion "20.0.0"
defaultConfig {
applicationId "org.nirvanasoftware.donor_app"
minSdkVersion 8
targetSdkVersion 20
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:20.0.0'
compile 'com.android.support:support-v4:20.0.0'
}
**build.gradle New **
apply plugin: 'com.android.application'
android {
compileSdkVersion 20
buildToolsVersion "20.0.0"
defaultConfig {
applicationId "org.nirvanasoftware.donor_app"
minSdkVersion 8
targetSdkVersion 20
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.3'
compile 'com.android.support:support-v4:21.0.3'
}
Is the change in dependency causing build errors or something else.
In the dependencies you have used appcompat-v7:21.0.3 and support-v4:21.0.3
But your compileSdkVersion is 20 buildToolsVersion is "20.0.0"
As I know if you use compileSdkVersion 20 then you should use buildToolsVersion "20.0.0" and the version of support library should also be 20 not 21. If you want to use appcompat-v7:21.0.3' and support-v4:21.0.3' you must use compileSdkVersion 21 and buildToolsVersion 21.x.y (here x and y will be the number according to your build tools that you have installed on your computer)
I am not sure that all of your problems are caused for this. But if there is a problem in your gradle synchronization then suddenly you will have a lot of problems. So if you do not have errors other than your gradle build file then your problems should be removed.
My suggestion is if you want to use latest SDKs and Support libraries install the latest build tools and SDKs from the Android SDK Manager then use
compileSdkVersion 21
buildToolsVersion "21.1.2" // your latest build tools
and dependencies like this
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.3'
compile 'com.android.support:support-v4:21.0.3'
}
Hope it will solve your problems. Happy coding :D
In addition: In the latest gradle version that is gradle-1.0.0 runProguard is a deprecated method. So instead of using it you must use minifyEnabled and update your gradle version to 1.0.0.

Categories