gradle error in unity exported android project - android

I am going to use the build config property "multiDexEnabled true" to break 64K methods limit following link
https://developer.android.com/studio/build/multidex.html#about
I update to use unity 5.6.1f1 and android studio 2.3.3. I set "build system" option to "Gradle(New)", which is new added from 5.5, then click "Export" to create an android project.
I open the exported project with android studio, then I get the following error
I try the two blue links, but I keep geting this same result.
For my unity project, I only create an empty project and add a button to a unity scene, then export it. I have also tried to build API directly, it works.
It is important for me to export unity project to andoid studio project, because it can help us to use additional compile options
Do any one know what I miss? Or how to export unity project correctly?
Thanks
The gradle error text, if cannot see the image link
Error:org.gradle.api.internal.tasks.DefaultTaskInputs$TaskInputUnionFileCollection cannot be cast to org.gradle.api.internal.file.collections.DefaultConfigurableFileCollection
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 had the same issue with unity 2017.1.0b4 and Android Studio 2.3.3, gradle 3.3.
You should change android plugin for graddle version in Android studio to 2.3.3
You can specify the Android plugin for Gradle version in either the
File > Project Structure > Project menu in Android Studio, or the
top-level build.gradle file. The plugin version applies to all modules
built in that Android Studio project. The following example sets the
Android plugin for Gradle to version 2.3.3 from the build.gradle file:
buildscript {
...
dependencies {
classpath 'com.android.tools.build:gradle:2.3.3'
}
}
https://developer.android.com/studio/releases/gradle-plugin.html

Check your local gradle version in directory -
C:\Users\yourname\.gradle\wrapper\dists
Modify your project gradle configuration -
project\gradle\wrapper\gradle-wrapper.properties
distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
Make sure gradle-3.3-all match to your gradle version.

If you have wasted a lot of time fixing unity Gradle error but nothing worked then you tried unity internal builder but that gave "Parsing Package error"
then try this, it will not help you make your project using unity's Gradle but it will make your project without any error successfully.
Export your project from unity to a folder eg: ProjectName_Gradle.
open android studio, make sure you are connected to the internet .
close current project then select "Open Gradle, eclipse ADT, etc;" option and open ProjectName_Gradle folder.
check the version of buildTools installed in your android-SDK by opening android-SDK settings from the android studio itself.
edit "build.gradle" file under Gradle Scripts section or under your project.
and change "buildToolsVersion" to the latest version installed in your SDK.
then click "syn project with Gradle Files" from file option and let it sync.
it may ask to update Gradle version, then click update
now there should not be any errors.
now try building APK.

Related

Could not determine the class-path for interface com.android.builder.model.AndroidProject

When I import an Eclipse project into Android Studio, I got this problem:
Gradle 'XNote' project refresh failed
Error:Could not determine the class-path for interface com.android.builder.model.AndroidProject.
Anyone knows why it happened? Thanks!
Just now i am facing the same problem.
1.Check classpath in build.gradle file.
change to
classpath 'com.android.tools.build:gradle:2.3.0'
then go to gradle-wrapper.properties, and change distributionUrl
distributionUrl=http://services.gradle.org/distributions/gradle-3.3-all.zip
and then rebuild the project. its help for me...
I think this will definitely helps you.
I have solved this problem.
Google doesn't update ADT any more, so when Eclipse export a project to gradle, it use an old gradle plugin version that Android Studio doesn't support.
First, you should check the version of gradle plugin that you have installed.
Open Android Studio's installation directory,then open the directory \gradle\m2repository\com\android\tools\build\gradle\, you will see all version you have installed.
Then open Android Studio, open tab 'Project -> Gradle Scripts', Edit file build.gradle, change the gradle plugin to newest version you have installed, such as 2.3.0:
[OPTIONAL] This step is not necessary, but if you do not do this, you may see this problem:
A problem occurred evaluating root project 'XXX'.
> org/gradle/initialization/BuildCompletionListener
Check the newest version of gradle you have installed at C:\Users\YOUR USER NAME\.gradle\wrapper\dists.
Then open tab 'Project -> Gradle Scripts', edit file gradle-wrapper.properties, modify the gradle version(attention: gradle, NOT gradle plugin) to the newest at the last line.
Finally, click Build - Clean Project, done!
If it still warning "Gradle project sync failed...", just click Try Again!
AT THE END, SOMEBODY HELP ME TO TRANSLATE MY ANSWER TO REAL ENGLISH THAT NO grammatical mistakes!!!
Just Update two things:-
1) Update your Build.gradle to
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
}
2) Update Gradle-wrapper.properties: (Change Android mode > Project mode then Extend Gradle and open Gradle-wrapper.properties)
Replace distributionUrl=http\://services.gradle.org/distributions/gradle-1.12-all.zip
By
distributionUrl=http://services.gradle.org/distributions/gradle-3.3-all.zip
This always resolves the issue. may it usefull for you
I got it working after upgrading build tools to version 25.0.0 in build.gradle:
buildToolsVersion '25.0.0'
And change project to use newest gradle version 3.3 with default gradle wrapper (File -> Settings -> Gradle)
In my case I removed folder .idea from the project and then restarting the studio automatically manages to all the required folder and gradle work.
First, delete your .gradle folder in the home directory then restart Android Studio.
Palanivelraghul was right. A Studio has to download the old version. Then it presented 3 different options after it was complete.
Choose the top option ~"Sync with 3.0.1".
Event Log:
Gradle sync started > Project setup started > Gradle sync finished > Executing tasks:
[:app:generateDebugSources, :app:generateDebugAndroidTestSources, :app:mockableAndroidJar] > Gradle build finished.

Downgrade Gradle from 3.3 to 2.14.1

Long story short: My android phone keeps disconnecting from ADB. I was told to update android studio, did that. I open my project in Intellij and try to run on android and I get an error:
BUILD FAILED
Total time: 48.986 secs
Error: /Users/me/Desktop/comp/Development/comp-ionic/platforms/android/gradlew: Command failed with exit code 1 Error output:
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':compileDebugJavaWithJavac'.
> java.lang.NullPointerException (no error message)
My first thought is that my gradle is the wrong version. For this specific app, I need to use gradle version 2.14.1.
When I type gradle -v I'm getting version 3.3.
Is there a way to delete/downgrade gradle from 3.3 to 2.14.1?
Or is this another problem?
If you're using the gradle wrapper, then there'll be a folder in your project named "gradle" with a subfolder named "wrapper", inside that, there are 2 files:
- gradle-wrapper.jar
- gradle-wrapper.properties
Open "gradle-wrapper.properties" and change the place where it says "3.3" to "2.14.1". Then sync gradle, and it will automatically download 2.14.1.
If you're using the new 2.3 Android Studio, you HAVE to use gradle wrapper 3.3, as its the minimum supported gradle wrapper version. If so, then you'll have to download Android Studio 2.2, or fix whatever issue you have in your project that needs gradle wrapper version 2.14.1.
To get more information about whatever the issue is, try running this:
./gradlew clean assemble -stacktrace
That will clean your project, try and compile it, and if/when it fails, it will show you a stacktrace of the error.
What you should do is to change the gradle build tools version to the one that matches your gradle version. According to here you can set the gradle to 2.14.1 by changing build tools to lower than 1.0.0.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.0.0'// For gradle 2.2.1 - 2.3
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
Notice: if you keep checking the mentioned link you'll see Higher is better for gradle.
For me, Android Studio > File > Invalidate Caches / Restart did the trick.
I got the same problem when upgrading to Android Studio 2.3.1. There is something funky about Gradle 3.3 (It fails by "java.lang.NullPointerException: null value in entry: destinationDir=null at com.google.common.collect.CollectPreconditions.checkEntryNotNull(CollectPreconditions.java:33)").
Good news: seems like the current most recent version (3.5) works.
Go to File|Project Structure|Project, and use these versions:
Gradle version=3.5
Android Plugin version=2.3.1
I update the Android Studio version to 3.3 Canary 4, then update the gradle plugin, and the project stops working.
I do not know how to restore my AS to the previous state, nighter the gradle plugin.
But just with this command, the project now works, for me: gradlew clean assemble -stacktrace, in terminal tab in AS.

Gradle build failing after update to Android studio 2.3 Canary 3

I've recently updated the android studio version of my project from 2.3 Canary 2 to 2.3 Canary 3. Since then the gradle build is failing every time with this error:
Error:Unable to find method 'org.gradle.api.tasks.Sync.getInputs()Lorg/gradle/api/internal/TaskInputsInternal;'.
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've searched google and not found solutions like this exactly but those that are similar are not working. Does anyone know how to fix it?
The solution is to select "Use default gradle wrapper (recommended)" option in the build gradle panel like the image below.
Now you can build with gradle 3.2 (in your gradle-wrapper.properties) and android gradle:2.3.0-alpha3 or beta1 as the time of writing
Don't forget to invalidate cache if you have some trouble using File -> Invalidate Cache / Restart
I had the same problem, fixed with checking gradle home path. This cannary build is no more working with gradle-2.14.1
The below link shows, point gradle path to gradle 3.2 directory.
The problem is the last version of tools 2.3.0-alpha3.
Try to use the 2.3.0-alpha2 in project build.gradle
classpath 'com.android.tools.build:gradle:2.3.0-alpha2'
It's mostly happened when setup new or update version of Android studio. I tried almost all solutions and find some fact that I like to share. It's work for me.
Make sure that updated JDK has set up to your computer and set path location.
Control Panel\System and Security\System-> Advanced system setting -> Advanced -> Enviroment Variables -> edit Path and pest your JDK bin folder location
Ex: C:\Program Files\Java\jdk1.8.0_131\bin
Set Project-level-setting "Use default Gradle wrapper (recommended)" from,
Android Studio -> File -> Setting -> Build, Exeution, Deployment -> Gradle
Set Android Studio JDK location:
Android Studio -> File -> Project Structure -> SDK Location -> JDK location
If this three thing is done then you need to set Gradle version 3.4.1 or see the latest version from gradle.org/releases.
Android Studio -> File -> Project Structure -> Project -> Gradle Version
After complete setting clean cash Android Studio will recover it own.
Android Studio -> File -> Invalidate caches/ Restart...
If you're using the gradle wrapper, make sure that the distributionUrl in your gradle/wrapper/gradle-wrapper.properties is correct and up to date. As of this writing, I use this:
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
try upgrading the Gradle version to 3.2.1
You may face this problem with your previous Project, We will notice that when you create a new application the Gradle build will complete successfully.
So just copy paste the grade setting from new project to the previous project.
Steps:
1) Replace Dependencies in build.gradle (project) by this code :
classpath 'com.android.tools.build:gradle:2.3.0'
2) Replace distributionUrl in Gradle-wrapper.properties by this code:
distributionUrl=https://services.gradle.org/distributions/gradle-3.3-all.zip
3) Don't forget to use Gradle default wrapper in Project level setting.
See this picture for more information
When updating to android studio 2.3, and then load an existing project for older version of android studio, It might take long if not forever on refreshing project.
I had the same problem but i fixed it as follows:
first of all go to Gradle Distributions and download any gradle of
version greater than 3.2
extract it and save it in a suitable place in your computer.
go to android studio and choose the following path
File->Settings->Build,Execution,Deployment->Gradle
on the right side choose or select Use local gradle distribution
and then browse to where you had saved your downloaded extracted
gradle
click apply, then ok.
thats it, your project should now work normally.
change
build:gradle:
from
dependencies {
classpath 'com.android.tools.build:gradle +'
to
dependencies {
classpath 'com.android.tools.build:gradle:2.2.3'

Gradle's dependency cache may be corrupt (this sometimes occurs after a network connection timeout.)

I am getting this kind of error, how to fix it.
Error:Unable to load class 'org.gradle.tooling.internal.protocol.test.InternalTestExecutionConnection'.
Possible causes for this unexpected error 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 updated my Android Studio to 2.3 and it asked me to update my gradle plugin to 3.3 that created issues with my running projects.
I've gone through all the Stack solutions and nothing worked for me except this workaround:
I changed my distribution url in gradle-wrapper.properties with this one.
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.2-all.zip
(permanent link list here : https://services.gradle.org/distributions/)
My project is up and running.It just asked me to update to gradle build tools 25.0.0 which I did so. Everything is fine now :)
Go to the project section and select gradle scripts menu.
Under script, menu select gradle -wrapper.properties
Then replace the distributionUrl=https://services.gradle.org/distributions/gradle-2.2-all.zip with "distributionUrl=https://services.gradle.org/distributions/gradle-3.4.1-all.zip"
note: distributions gradle will change depended upon the version of the android studio.
Make sure you have Internet Connection then:
1.For Window Users Go to > C:\Users\username\.gradle\wrapper\dists
2.For Linux users
Go to $HOME/.gradle (~/.gradle) and/or (Under Specific project)
<PROJECT_DIR>/.gradle
3.Delete the gradle file(s) with the problem(i.e the zipped folders with
missing with no its extracted file )
4.Sync the project with gradle files.
Delete corrupt files
This error occurs when Gradle files are not completely downloaded or corrupted by some other reason, so we have to redownload the files.
The easy way is to delete the old files in
C:\Users\username.gradle\wrapper\dists
and rebuild the project, Android Studio will automatically download the new files.
Watch the Tutorial
https://www.youtube.com/watch?v=u92_73vfA8M
or
follow steps :
Go to any browser
type gradle and press enter
you can specify any version you want after the
gradle keyword
i am downloading gradle 3.3
https://services.gradle.org/distributions
click on this link which is in description directly if you want
click on gradle 3.3 all.zip
wait for the download to complete
once the download is complete
extract the file to the location
c://user/your pc name /.gradle/wrapper/dists
wait till extraction it takes 5 mins to complete
Now open your project in android studio
9.go to file > settings >bulid ,exec,deployment > gradle
now change use default gradle to
use local gradle distributn
select the location where you had extracted gradle 3.3.zip
C:\Users\your pc name.gradle\wrapper\dists\gradle-3.3
click on OK
Now build starts again and
you can see now the build is successful and error is resolved
If you manually setup gradle also make sure projects build.gradle verison is compatible with it. See following as an example.
Project's build.gradle
dependencies {
classpath 'com.android.tools.build:gradle:2.3.2'
}
Manual gradle setup
A lot of answer to this questions but a few were helping. I want to give accurate and updated answer.
Gradle's dependency cache may be corrupt (this sometimes occurs after a network connection timeout.)
This error happens when you bad internet connection or you put your computer to sleep while Android Studio is downloading the required dependencies.
How to resolve this issue.
Find out the project's Gradle version. You will find that in gradle-wrapper.properties in distributionUrl my gradle distribution was https\://services.gradle.org/distributions/gradle-6.5-all.zip that means gradle-6.5-all.zip is required to download and right now it is corrupted because of connection timeout. Lets find out this folder and delete this.
Go to $HOME/.gradle folder then to wrapper then to dists then find a folder that matches the gradle version name that required to download. In my case it was gradle-6.5-all.zip select this folder and delete it.
Now sync the project and make sure you have good internet connection and setting that will prevent your system going to sleep while downloading something.
Kindly delele all folders under the in /.graddle/version/
This is how i solved mine. good luck
Maybe you can run ./gradlew build -s in the terminal, the stacktrace would show you where went wrong.
Try the next step to "Refresh" your IDE (android studio)
1. Let Gradle rebuild your auto-genrated files by click Build | Rebuild
2. Also try Choose File | Invalidate Caches/Restart.
I resolved this issue by downloading current version of graddle from link given
download latest version of graddle possibly graddle 3.3
Then in next step i accessed .graddle/wrapper/dists dirctory from home directory on my Mac after showing up hidden system files and deleted previuos version folder residing there.
Now i put that downloaded latest version folder after uncompressing there.
Now restarted Android studio and problem was resolved.
If you are seeing this error in Android Studio 4.1 with Gradle 6.5 then you should move back to
classpath 'com.android.tools.build:gradle:4.0.2'
For some reason
classpath 'com.android.tools.build:gradle:4.2.0'
does not work correctly.
You can try this
first Open your Android Studio > open any project you're doing
click on File > Settings > Build,Execution,Deployment > Gradle
At Project-Level settings , there are 2 option to sync the gradle either usin the default or local.
now change from default to a local gradle distribution > gradle Home
select the path on your computer.
C:\Program Files\Android\Android Studio\gradle\gradle-4.1
click on OK
Now build starts again it should be solved.
Go to "C:\Users\.gradle\caches\". Delete all the files in the folder. Then Sync Gradle and Rebuild the project.
i deleted the gradle folder and then i did rebuild, every thing working fine
If you using Ubuntu, So firstly you have unhide all files from your home directory or where located your android studio folder :
Go to your home directory and unhide all files by using ctrl+h
You found .gradle folder
Inside .gradle -> wrapper
You can found dists folder, So delete this dists folder
Create a New Project than your Gradle file re-downloaded
Congo you successfully build project
check out distributionUrl setting in gradle-wrapper.properties. I changed https to http, then my problem was solved.
In my case,just change http to https in the gradle-wrapper and Sync it.
Just reimport project. :)
I tried cleaning up the cache and refreshing dependencies doesn't work but failed.
Clear .gradle folder and rebuild
Open C:\Users\Username.gradle\wrapper\dists\
Open latest gradle folder, e.g. gradle-4.1-rc-1-all
You will find a random folder named 936kh1brdchce6fvd2c1o8t8x
Download zip file of similar name
eg: https://downloads.gradle.org/distributions/gradle-4.1-rc-1-all.zip
Save it in this folder
Restart Android studio
It will automatically extract the zip folder and Error will clear
Finally solved this problem.
If you just copy new version's files to old folder and override files,you may face the same question as me.
To solve it:
makesure you saved your all settings.
close AS,DELETE ALL files of your mixed version.
extract new version to your empty folder.
It works for me.
For me, i was cloning a project from github which used a version of gradle higher than that which i had installed. I had two choices:
Open gradle.wrapper-properties of a project you have that's building successfully, and copy the line that says distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.1-all.zip. Use this to replace the same value in the project that's failing. That should do the trick.
Your build might still fail if the gradle version used to build the project is higher than that which you just added. For this you should update the gradle version to the latest.
In my case I hade to change from:
plugins {
id 'com.android.application'
id 'kotlin-android'
id 'kotlin-kapt'
**apply plugin :'com.google.gms.google-services'**
}
to
plugins {
id 'com.android.application'
id 'kotlin-android'
id 'kotlin-kapt'
id 'com.google.gms.google-services'
}
search on google "download java 11"
click oracle website download your java to your platform and install it.
go to android studio click CTRL+SHIFT+ALT(Project Structure)
SDK Location Tab Show the path of JDK location which you installed
In your gradle-wrapper.properties
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-bin.zip
This won't download and always gives 'gradle cache corrupt' error, but a small change makes it work fine
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-all.zip
Now sync the gradle again and it's done.
I will generalize the issue that you might face
Inside module's build.gradle :
Change:
plugins {
[...]
apply plugin:'whatever_you_have'
}
to
plugins {
[...]
id 'whatever_you_have'
}
In other words instead of apply plugin: use id
Unable to find method ''void
com.android.build.api.extension.AndroidComponentsExtension$DefaultImpls.androidTest$default(com.android.build.api.extension.AndroidComponentsExtension,
com.android.build.api.extension.VariantSelector,
kotlin.jvm.functions.Function1, int, java.lang.Object)'' 'void
com.android.build.api.extension.AndroidComponentsExtension$DefaultImpls.androidTest$default(com.android.build.api.extension.AndroidComponentsExtension,
com.android.build.api.extension.VariantSelector,
kotlin.jvm.functions.Function1, int, java.lang.Object)'
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.
It happened to me after upgrading Android Studio to 4.2.0.
Updating the hilt classpath on build.gradle to 2.35 fixed these issues for me.
classpath "com.google.dagger:hilt-android-gradle-plugin:$2.35"
If you have updated your android studio, then go to FILE, Project Structure, Project, then check gradle version. Before that check your gradle version in C:\Program Files\Android\Android Studio\gradle and check the version if it matches then sync again else change the gradle version in android studio and sync again.
I had a similar problem after cloning AnySoftKeyboard and opening it in Android Studio. What worked for me was deleting the AynSoftKeyboard/gradle folder and then cleaning the project via menu item Build > Clean Project.
So try deleting YourProject/gradle folder and clean the project to trigger a Gradle sync.
Hope it works for your case.
download gradle from here for your OS and extract the file and paste the inner folder into installLocation/gradle
than in Android Studio Goto File > Settings > bulid ,exec,deployment > gradle and choose local gradle option and provide the file path of your new downloaded gradle and hit ok it works :)

Import a project to Android studio faced problems

I want reading an open source project so I select k9mail for start. The recommendation was run and reading this code in Android Studio. I import k9mail project to AS 1.2.1.1 version. I download gradle 2.4 version and added this in environment variable. When I want to run this application, but I receive some errors that I describe below:
1) When I click Run (Alt+Shift+F10), select Android Application, select my module (there is k9mail) and select USB Device, then I see a warning:
No JDK specified for module 'k-9-master'.
2) When I click on Run (Shift+F10), I faced this error in messages tab:
Gradle DSL method not found: 'android()'
Possible causes:
A)The project 'k-9-master' may be using a version of Gradle that does not contain the method.Open Gradle wrapper file
B)The build file may be missing a Gradle plugin. Apply Gradle plugin
When I updated gradle to 2.4, I changed classpath 'com.android.tools.build:gradle:1.2.3' to 'classpath 'com.android.tools.build:gradle:2.4'' from build.gradle of k9mail, but my problems were not solved.
I googled but I can't find solutions for my problems.
No jdk specified for the module.
For that you have to specify the jdk path through Project Structure.
You may also verify by looking at local.properties
For gradle related issues you just kindly update your gradle build and SDKs to latest versions.
This will minimize your gradle issues.

Categories

Resources