Gradle wrapper version issues - java

My task is to build an apk file using gradle wrapper via command line. I have a project in Android Studio 2.2.3, it has a line in build.gradle file classpath 'com.android.tools.build:gradle:2.2.3', which should mean, that it is using gradle version 2.2.3. But when I call gradlew command from the project folder, there is always the same error: Unsupported major.minor version 52.0
I've used gradlew -v to recognize my gradle version, it is now 2.2.1. Though when I manually change gradle version in build.gradle file from 2.2.3 to 2.2.1 I still get the same error.
I checked the folder containing gradle on my computer. It has gradle version 2.14.1.
I tried:
changing JDK path from 1.7 to 1.8 (JAVA_HOME variable)
manually changing JDK location at Project Structure -> SDK Location settings
in gradle settings: switching between using default gradle wrapper and local gradle distribution.
Interesting thing is that when I change gradle version in build.gradle to 1.5.0 the version error disappears, but I can no longer make any builds(it becomes unable to merge several jar files into one apk file)
What is this version hell and how do I get rid of this error?
EDIT #1:
My /gradle/wrapper/gradle-wrapper.properties content is:
#Fri Oct 21 12:53:56 EEST 2016
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip
EDIT #2:
I figured out that gradle versions are the same. So what JDK and JRE version should I use and how do I update them? Simply downloading into Java folder and changing JDK location in Project Structure didn't help.
EDIT #3:
My build.gradle file:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
mavenCentral()
flatDir {
dirs 'libs'
}
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.3'
classpath 'com.google.gms:google-services:1.5.0-beta2'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
flatDir {
dirs 'libs'
}
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
My project-level build.gradle file:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
defaultConfig {
applicationId "com.test.test"
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'])
compile 'com.android.support:design:23.4.0'
compile "com.android.support:support-v4:23.4.0"
compile 'junit:junit:4.12'
compile 'com.google.android.gms:play-services-ads:8.4.0'
}
SOLUTION:
I needed to update targetSdkVersion and all dependencies to version 25 and set JAVA_HOME to jdk 1.8. Thanks, Abhishek Aryan

Gradle version is different from Android Plugin for Gradle version.
This is Android Plugin for Gradle with version
classpath 'com.android.tools.build:gradle:2.2.3'
And gradle with version
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip

Related

Android Studio 2022 Gradle Problems

it's been 3 days I'm struggling with this problem and didn't find a single solution to this.
Everything was good I had many projects in android studio 2022 working well but suddenly it seems all of my Gradle files are changed ?! or they are just I don't know what happened to them they are broken! every single project I open even the new project gives me an error in every single dependency or plugin ill share the information about it below here:
Every single Build.Gradle (Project) File :
// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
id 'com.android.application' version '7.2.1' apply false
id 'com.android.library' version '7.2.1' apply false
id 'org.jetbrains.kotlin.android' version '1.7.10' apply false
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Sample build.Gradle (App)
plugins {
id 'com.android.application'
}
android {
compileSdk 32
defaultConfig {
applicationId "com.teach.mytest"
minSdk 28
targetSdk 32
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
implementation 'androidx.appcompat:appcompat:1.5.1'
implementation 'com.google.android.material:material:1.6.1'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}
** Sample gradle-wrapper.properties:**
distributionBase=GRADLE_USER_HOME
distributionUrl=https://services.gradle.org/distributions/gradle-7.6-rc-1-bin.zip
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
** Sample settings.gradle: **
repositories {
gradlePluginPortal()
google()
mavenCentral()
}
}
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
}
}
rootProject.name = "MyTest"
include ':app'
Errors:
simple explaining about errors The errors are simply coming for all the projects are the same but when one project has extra dependency it gets errors like the below too for that dependency
also when I change the Gradle version from properties it's downloading the new Gradle working well but in the build phase it gives the same errors
Plugin [id: 'com.android.application', version: '7.2.2', apply: false] was not found in any of the following sources:
Gradle Core Plugins (plugin is not in 'org.gradle' namespace)
- Plugin Repositories (could not resolve plugin artifact 'com.android.application:com.android.application.gradle.plugin:7.2.2')
Searched in the following repositories:
Gradle Central Plugin Repository
Google
MavenRepo
** Whatever i did ?**
I tried to create a new project
I tried to change the java version
I tried to change the Gradle version and the application version
I tried to invalidate caches and restart
** Notes **
I'm using Java 15 mainly in my projects default android studio java version is 11
I change it via setting > build tool
But the problem is same also same in kotlin projects
Edit:
I changed the android.application version to 7.0.0
everything downloaded started from scratch at the final part its giving only error for gradle version 7.0.0

getting red line in files after upgrading to gradle 4.4 and gradle build tools version 3.1.2

The Android studio ask me to update the gradle version to 4.4 and gradle build tool version to 3.1.2.
After the update, The whole android studio shows red lines in file, when I hover my cursor on these error it says "cannot resolve symbol" but compiles with no error i.e., build is successful.Click here to see red lines in java files
and Here are the gradle app and project files.
//Build.gradle(project)
//Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
maven {
url 'https://maven.fabric.io/public'
}
jcenter()
maven {
url 'https://maven.google.com/'
name 'Google'
}
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.2'
classpath 'com.google.gms:google-services:3.2.0'
classpath 'io.fabric.tools:gradle:1.25.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
maven {
url 'https://maven.google.com/'
}
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
and
//build.gradle(module:app)
apply plugin: 'com.android.application'
android {
compileSdkVersion 27
buildToolsVersion '27.0.3'
defaultConfig {
applicationId "com.developers.paras.droidwatch"
minSdkVersion 19
targetSdkVersion 27
versionCode 9
versionName "9.0"
multiDexEnabled true
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled true
shrinkResources true
android.defaultConfig.vectorDrawables.useSupportLibrary = true
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-annotations'
})
compile 'com.android.support:appcompat-v7:27.1.1'
compile 'com.android.support:customtabs:27.1.1'
compile 'com.android.support.constraint:constraint-layout:1.1.0'
compile 'com.android.support:design:27.1.1'
compile 'com.android.support:support-v4:27.1.1'
compile 'com.google.android.gms:play-services-ads:15.0.1'
compile 'com.google.firebase:firebase-core:15.0.2'
compile 'com.crashlytics.sdk.android:crashlytics:2.9.2'
testCompile 'junit:junit:4.12'
}
apply plugin: 'com.google.gms.google-services'
apply plugin: 'io.fabric'
Things I have already tried.
Clean and Rebuild.
Invalidate Cache and Restart.
Updating gradle version to 4.9.
Setting local gradle for the project.
See my gradle logs here https://drive.google.com/open?id=18bFZdkWX4AFPfpmfjvN1t80WpVRpiHWs
See even release build is generated after these errors. Release apk generated
Update : Recently after Reinstalling Studio, I've created a new project and everything works fine. No errors for "cannot resolve symbol".
not the most graceful solution in the world but deleting and re-cloning the project was the fastest way to resolve this for me.
if you're not using git... well. now is a good time to start.
I tried deleting and re-syncing all the various config files and it didn't do anything.
I got into similar situation: upgraded Gradle to 4.4, then opened a former porject which had been built with Gradle 3.1.2.
Android Studio noticed it and generously offered:
To take advantage of all the latest features (such as Instant Run), improvements and security fixes, we strongly recommend that you update the Android Gradle plugin to version 3.1.2 and Gradle to version 4.4.
When I choose to update, I got the red underlines showing errors everywhere in MainActivity.java, however the project was building and runnig perfectly.
I also tried to rebuild and to invalidate cache & restart, but had no success.
For me, editing the build.gradle (module:app) file helped.
When I modified both compileSdkVersion and targetSdkVersion to the latest (27) and changed the version number of line implementation 'com.android.support:appcompat-v7:2x.x.x' under dependencies to the latest, then resynced, the red lines suddenly disappeared from MainActivity.java and everything became normal.
Maybe not the fiddling with sdk version numbers are important here, but to force a proper gradle resync.
Please note also, that since Gradle 3.4, under dependencies in build.gradle file some configuration words changed: compile, testCompile, androidTestCompile, testApi, androidTestApi become obsolete and should be replaced with implementation or api.
You can find more on this issue here: https://developer.android.com/studio/build/gradle-plugin-3-0-0-migration?utm_source=android-studio#new_configurations and a proper explanation on the difference between choosing implementation or api here: https://medium.com/mindorks/implementation-vs-api-in-gradle-3-0-494c817a6fa

Android Studio keeps generating Eclipse-like files

I'm using Android Studio 3.0.1 and I have noticed that for one of my projects (only this one) it generates .project files and a bin directory like Eclipse does (I suppose).
The project was created in AS 3.0.1 and it was not migrated from Eclipse or anything like this. It also doesn't use any fancy Gradle plugins or dependencies - just the generated ones (AppCompat + Kotlin).
Do you have any idea why it does so?
Also, when I was trying to prepare a minimal project for reproduction, I noticed that the problem disappears just by copy-pasting the whole project directory so there's probably no point in sharing it with you.
Using two project copies (let's call them original and copy) I was able to find out that when I close Android Studio and clean both copies using git clean -xfd
copy has no issues when opened - no Eclipse-like files
original still has the issue when opened (files get generated)
diff -r before opening them (so just after git clean) gives only this:
Binary files ../PWTA_Proj2/.git/index and ./.git/index differ
both of them make Android Studio show an error like this when opened:
Unsupported Modules Detected: Compilation is not supported for following modules: PWTA_Proj2. Unfortunately you can't have non-Gradle Java modules and Android-Gradle modules in one project.
Despite of the error I can build the project normally. Also I don't have any non-Gradle modules - the project is very simple and generated by AS. The only less common thing is that the project contains a few AIDL files.
Edit #1: Gradle files:
top-level build.gradle:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.kotlin_version = '1.2.0'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
top-level settings.gradle:
include ':app'
app module build.gradle:
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 27
buildToolsVersion '27.0.3'
defaultConfig {
final appId = "com.azabost.pwta.proj2"
applicationId appId
minSdkVersion 25
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
manifestPlaceholders.tspProcessName = appId + ".tsp"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation"org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
implementation 'com.android.support:appcompat-v7:27.0.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
}

Gradle Build failed: Task 'stacktrace' not found in root project

I know this question is asked many times, and i used all the Answers to to resolve my error. Here is my problem.
I tried almost all Answer present on So, so please before mark my question as Duplicate, please read my question care, i mentioned all steps that are answered on SO Questions.
Whenever i tried to run / build / clean project i got error * What went wrong:
Task 'stacktrace' not found in root project 'project'.
Library and Sdk i m using
ViewPagerIndicator - JakeWharton
Facebook SDK
PDK (Pinterest sdk)
gcm.jar
httpcore-4.4.4.jar
What i have tried so far
changed Gradle version from 2.2.1-all.zip to lower version
changes Gradle Build version
delete all Library and run
All library project minSdkVersion same (my project using minSdkVersion: 11 )
clean project and Rebuild
Invalidate cache and restart Android Studio
delete .idea and .gradle folder then Import project
Created new project and copy paste old Project into project but it also gives same error on build
deleted .gradle folder from user folder(i m using windows 7 )
try to build project using command line
Changed JDK version new jdk1.8.0_73 ( my project was build on jdk1.7.0_55 ) here is thread that said using new JDK version will resolve problem
here are Answers i follwed first solution , Second solution, third solution Fourth Answer and many more.
Temporary solution(it was working before but not now )
i have backup of project two week ago, i import that backup project and replace the files and it works
But when i do clean project error came again
here is app level build.gradle file
apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "XXX"
minSdkVersion 11
targetSdkVersion 23
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:design:23.1.1'
compile 'com.android.support:support-v4:23.1.1'
compile project(':library')
compile files('libs/picasso-2.5.2.jar')
compile files('libs/jsoup-1.8.3.jar')
compile files('libs/httpcore-4.4.4.jar')
compile 'com.google.android.gms:play-services:8.3.0'
compile files('libs/gcm.jar')
compile 'com.facebook.android:facebook-android-sdk:[4,5)'
}
android {
useLibrary 'org.apache.http.legacy'
}
Here is proejct level builld.gradle file
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.5.0'
classpath 'com.google.gms:google-services:1.5.0-beta2'
}
}
allprojects {
repositories {
jcenter()
}
}
Help will be Appreciated!. Please share your ideas to resolve this error
i m trying to deal with error from 1 week and i m not getting answer from anywhere that will work for me
thanks

Android Studio 0.3.2: gradle compile problems

I just updated Android Studio to version 0.3.2. My project uses Gradle version 1.8.
On the picture below you can see that it is configured in gradle and Android Studio resolver http-async package but gradle fails with Gradle: package com.loopj.android.http does not exist
I tried already
to remove android-async-http and adding it as Library again,
to include fileTree(...) in gradle configuration file,
Rebuilt project but nothing helped
Though if absolute path is set gradle works just fine.
Gradle file
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.6.+'
}
}
apply plugin: 'android'
repositories {
mavenCentral()
}
android {
compileSdkVersion 18
buildToolsVersion "17.0.0"
defaultConfig {
minSdkVersion 11
targetSdkVersion 18
}
}
dependencies {
compile 'com.android.support:appcompat-v7:+'
compile 'com.android.support:support-v4:13.0.0'
compile 'com.android.support:support-v13:13.0.0'
compile 'com.google.android.gms:play-services:3.1.36'
compile files("libs/android-async-http-1.4.4.jar")
}
Can anyone help me with this?
Try to move the libs folder at the same level of src folder.
Android Studio have just released 0.3.7, which claims to have solved a lot of gradle issues such as adding .jar libraries
http://tools.android.com/recent
Hopefully this will help you!

Categories