Migrating to android studio 3.0.1 - android

Hello i am trying to migrate my project to android 3.0.1 how ever i get below error :
Error:(1, 0) Unable to find method
'org.gradle.api.Project.getPluginManager()Lorg/gradle/api/plugins/PluginManager;'.
Possible causes for this unexpected error include:Gradle's
dependency cache may be corrupt (this sometimes occurs after a network
connection timeout.) Re-download dependencies
and sync project (requires network)The state of a Gradle
build process (daemon) may be corrupt. Stopping all Gradle daemons may
solve this problem. Stop Gradle build
processes (requires restart)Your project may be using a
third-party plugin which is not compatible with the other plugins in
the project or the version of Gradle requested by the
project.In the case of corrupt Gradle processes, you can
also try closing the IDE and then killing all Java
processes.
I tried to add google() to repositories but got
no where
my gradle build is :
apply plugin: 'com.android.application'
android {
compileSdkVersion 20
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "com.example.flashlight"
minSdkVersion 14
targetSdkVersion 14
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}

Change your gradle-wrapper.properties to:
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip

Maybe the current gradle files are incompatible with your latest Android Studio version. You can just delete the .gradle folder as it is always created when the tasks are run. Deleting the folder will cause all the dependencies to download again (which will take some time) and then you can try to re-run the application.
You need internet connection for syncing and downloading the gradle files. Let me know if the error still persists.

This code is tested and it works :
change your gradle file like this :
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion '25.0.0'
defaultConfig {
applicationId "com.example.flashlight"
minSdkVersion 15
targetSdkVersion 25
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile 'com.android.support:support-v4:25.0.0'
compile 'com.google.android.gms:play-services:+'
}
alse in gradle-wrapper.properties file make distribution url :
distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
in build.gradle change com.android.tools.build:gradle version to :
classpath 'com.android.tools.build:gradle:2.3.2'

Finaly probleme solved , it was just a litlle probleme of gradle version , seems i had to update the source code manualy .
thanks guys

Related

Unable to Merge Dex - Android Studio 3

I'm running the application in Android 5.1 device and it's running well after some time i have uninstalled the android studio and now i have installed Android Studio 3.0.1 and working on Elementary OS Loki and trying to run it on Android 8.0 device and when I start new app and run it then all goes well but the existing project is not running it gives error while running
Error:Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'.
> java.lang.RuntimeException:
com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex
And I have build.gradle file as below
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
buildToolsVersion '26.0.2'
defaultConfig {
applicationId "za.co.neilson.alarm"
multiDexEnabled true
minSdkVersion 16
targetSdkVersion 26
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile 'com.android.support:appcompat-v7:26.0.0'
implementation files('lib/android-support-v7-appcompat.jar')
}
I have googled and tried other solutions like
multiDexEnabled true
And rebuild / clean project but it did not work
Since you are using compile 'com.android.support:appcompat-v7:26.0.0' there are no reasons to add the jar file (also pay attention since the aar contains the jar file but also the resources).
Remove this line:
implementation files('lib/android-support-v7-appcompat.jar')
and delete the lib/android-support-v7-appcompat.jar file
I have googled and tried other solutions like
multiDexEnabled true
It is completely useless in your case. Use it when your app and the libraries it references exceed 65,536 methods, not when you are adding twice the same classes.
Try to change your gradle version to 3.0.1 or 2.3.3. By changing to one of them it may work for you.
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
//or try classpath 'com.android.tools.build:gradle:2.3.3'
}
After this clean and rebuild the project.
Hope it helps you.

Gradle error when trying to compile an old project Android Studio

I am trying to re-compile one project that worked fine several months ago and I am getting a gradle error like this one:
Error:(1, 0) Unable to find method
'org.gradle.api.Project.getPluginManager()Lorg/gradle/api/plugins/PluginManager;'.
Possible causes for this unexpected error include:Gradle's
dependency cache may be corrupt (this sometimes occurs after a network
connection timeout.) Re-download dependencies
and sync project (requires network)The state of a Gradle
build process (daemon) may be corrupt. Stopping all Gradle daemons may
solve this problem. Stop Gradle build
processes (requires restart)Your project may be using a
third-party plugin which is not compatible with the other plugins in
the project or the version of Gradle requested by the
project.In the case of corrupt Gradle processes, you can
also try closing the IDE and then killing all Java processes
I have updated the gradle version in the build.gradle file (project) from
dependencies {
classpath 'com.android.tools.build:gradle:1.2.3'
}
to
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
}
I have followed the suggestions of AS with no luck.
Could you give an advice?
My build.gradle file (app) is:
apply plugin: 'com.android.application'
android {
compileSdkVersion 14
buildToolsVersion "22.0.1"
defaultConfig {
applicationId 'com.aabcdata.learn.german.hd'
minSdkVersion 14
targetSdkVersion 14
versionCode 6
versionName '1.5'
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
productFlavors {
}
}
dependencies {
compile files('libs/FlurryAnalytics_3.3.2.jar')
compile 'com.google.android.gms:play-services-ads:7.5.0'
compile files('libs/AppTracker.jar')
compile files('libs/presage-lib-1.6.0.jar')
}
I have done a Invalidate Cache/Restart, as well
I had that problem also in a very old project. You need to upgrade the gradle distribution version in your gradle-wrapper.properties file. I changed it from version 2.2.1 to 4.1.
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip

Gradle failed to sync with 'unable to find optional library'

I had to reinstall my system and today I get this error in Android Studio when I try to sync with gradle:
Warning: Unable to find optional library: org.apache.http.legacy
My project gradle is:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.3.0'
}
}
allprojects {
repositories {
mavenCentral()
}
}
And my module gradle:
apply plugin: 'android'
android {
useLibrary 'org.apache.http.legacy'
compileSdkVersion 23
buildToolsVersion '23.0.2'
defaultConfig {
minSdkVersion 16
targetSdkVersion 23
}
buildTypes {
release {
}
}
productFlavors {
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:support-v4:23.1.1'
compile 'com.android.support:appcompat-v7:23.1.1'
}
From the google docs:
To continue using the Apache HTTP APIs, you must first declare the
following compile-time dependency in your build.gradle file:
android {
useLibrary 'org.apache.http.legacy'
}
I tried the suggestions mention in this thread but they don't work. Same result with android studio 1.5 and 2 preview.
How can I fix this?
Edit: Things I've tried so far:
Change gradle classpath versions to 1.3.0, 1.3.1, 1.5.0.
Change the compileSdkVersion and targetSdkVersion to 22. Also the buildToolsVersion from 23.0.1, 23.0.0, 22.0.1.
Top level build.gradle - /build.gradle
buildscript {
...
dependencies {
classpath 'com.android.tools.build:gradle:1.3.1'
}
}
Module specific build.gradle - /app/build.gradle
android {
compileSdkVersion 23
buildToolsVersion "23.0.0"
useLibrary 'org.apache.http.legacy'
...
}
Add org.apache.http.legacy.jar which is in Android/Sdk/platforms/android-23/optional folder to app/libs directory and sync your project
After a lot of working this solutions work for me
.
** Studio\Android\sdk\platforms** here delete your android-23 and from sdk manager update api 23 again.**
.
it will solve your issue.
In my case, it didn't work because I was missing optional.json in <sdk-path>\platforms\android-23\optional\, directory with the following content:
[
{
"name": "org.apache.http.legacy",
"jar": "org.apache.http.legacy.jar",
"manifest": false
}
]
Creating a new JSON file with with above content solved the problem for me.
You need to add org.apache.http.legacy.jar jar file in your Android Stuido project's app/libs folder.
Jar Location - `<SDK LOCATION>\android-sdk\platforms\android-23\optional`
To do this, just right click on your project and select Show in Explorer then go to ...\app\libs and paste above jar file and Sync your Project with Gradle File
Module:app
android {
compileSdkVersion 'Google Inc.:Google APIs:23'
buildToolsVersion "24.0.0"
defaultConfig {
applicationId "<ur_app_id>"
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'
}
}
}
Update your project gradle file to use gradle version 1.3.1.
classpath 'com.android.tools.build:gradle:1.3.1'
Also try adding codehause repo.
repositories {
mavenCentral()
maven{
url 'http://repository.codehaus.org'
}
}
In my case the problem was actually occurring because I didn't have the correct SDK installed on that computer. Navigating to .../Android/Sdk/platforms/android-23 I could see that folder was empty. Adding SDK 23 via the SDK manager fixed the problem and allowed me to compile.
You should manually check that you have the same version of the SDK installed that is specified under compileSdkVersion in your build.gradle file.
To save time 2 solutions are best and works for me.
Solution 1 :
open your android sdk manager and reinstall API 23 (remove and install again).
Solution 2 :
Download this file which contain optional.json file
extract and move optional.json to :
C:\Users\\AppData\Local\Android\sdk\platforms\android-23\optional
if above solution is not work then try this way
I experienced this problem recently, and it is caused by the path length restriction I think it´s 256 characters maximum.
Relocate your Project and the build will succeed.
Copy "sdk\platforms\android-23\optional\org.apache.http.legacy.jar" to your app module libs directory, then add as library;
If you enable the proguard, please edit "proguard-rules.pro" to keep related classes or exception will occurred.

Android Studio 1.0 Gradle Error with getConfiguration()

I changed everything else as needed in my gradle files, but I'm hitting one error I can't seem to resolve:
Error:Unable to find method 'org.gradle.api.internal.project.ProjectInternal.getConfigurations()Lorg/gradle/api/internal/artifacts/configurations/ConfigurationContainerInternal;'.
Possible causes for this unexpected error include:<ul><li>Gradle's dependency cache may be corrupt (this sometimes occurs after a network connection timeout.)
Re-download dependencies and sync project (requires network)
The state of a Gradle build process (daemon) may be corrupt. Stopping all Gradle daemons may solve this problem.
Stop Gradle build processes (requires restart)
In the case of corrupt Gradle processes, you can also try closing the IDE and then killing all Java processes.
If it's of any help, here's my main build.gradle file:
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.1.1"
defaultConfig {
minSdkVersion 16
targetSdkVersion 21
versionCode 9
versionName "1.6"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile files('libs/gson-2.2.4.jar')
compile project('libs:anddown')
compile 'com.android.support:appcompat-v7:21.0.2'
compile files('libs/android-support-v7-recyclerview.jar')
}
I was able to resolve this error by upgrading to the lastest release of my android maven plugin:
buildscript {
repositories {
mavenCentral()
}
dependencies {
...
classpath 'com.github.dcendents:android-maven-plugin:1.2'
}
}
Cleaning project or gradle did not work for me. I had to change gradle distribution from 2.2.1 to 2.4.
In gradle-wrapper.properties file:
distributionUrl=https\://services.gradle.org/distributions/gradle-2.4-all.zip
I also had this issue.
This was resolved once I removed apply plugin: 'android-maven' from one of my build files.
The newest android studio requires gradle version 2.2+ , are you using this version ? If yes, try invalidate cache / restart on File menu.
If those previous answers don't work and you are upgrading your Android Studio, try to update the gradle/wrapper folder by creating a new project and copying this folder from the new project and overwriting to your old one. It worked for me.

Building app with library module cannot find AndroidManifest.xml

I want to build an Android App with AndroidAnnotations.
Here is a simplified version on GitHub which fails to build/pre-process: https://github.com/aiQon/androidannotationsexample
The app is composed of a main app module and a library module.
Both use AndroidAnnotations (AA). The lib module has a workaround to find the AndroidManifest.xml in debug builds (it refers to the release manifest, because gradle does not build the debug variant for libs).
However, the manifest is found for the library module but not for the main app.
The gradle file of the main app is:
apply plugin: 'com.android.application'
apply plugin: 'android-apt'
buildscript {
repositories {
mavenLocal()
mavenCentral()
}
dependencies {
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.4'
}
}
android {
compileSdkVersion 21
buildToolsVersion "21.0.1"
defaultConfig {
applicationId "de.stelle_beratung.androidannotationslibraryexample"
minSdkVersion 15
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
apt {
arguments {
androidManifestFile variant.outputs.processResources.manifestFile
resourcePackageName android.defaultConfig.applicationId
}
}
dependencies {
compile project(":mylibrary")
apt "org.androidannotations:androidannotations:3.2+"
compile 'org.androidannotations:androidannotations-api:3.2+'
}
Gradle complains with:
http://pastebin.com/QZtnHcZD
Could someone please point me in the right direction on how to build this simplified project to have a controller Bean in the lib module and reference it successfully in the main app activity by using AA?
I appreciate any help.
Since android gradle plugin 14.4, the following line does not work anymore:
variant.outputs.processResources.manifestFile orvariant.processResources.manifestFile
You have to use this one instead:
variant.outputs[0].processResources.manifestFile
Please note if you have multiple outputs (when using splits), you may want to use another output (other index than zero).
Ok I got it. Was using Android Studio from the Canary Channel. Going back to Beta solved the issue because I could use android gradle plugin 0.12.2. This solved everything.

Categories

Resources