Creating new Android Studio project get the following exception in Gradle build file:
Cannot resolve symbol 'GradleException'
Gradle still builds successfully, but still shows this error in editor.
What's missing from my project?
Android Studio 3.3.2
Gradle 4.10.1
compileSdkVersion 27
The latest Android SDK does not support GradleException(), instead use FileNotFoundException().
Or for future readers, maybe use RuntimeException (if the issue is not file related).
I found the issue and the solution on this GitHub thread:
https://github.com/flutter/flutter/issues/29608
Note: this answer is no longer up-to-date for newer versions of Android Studio and Gradle. See this answer instead.
Android Studio seems to have various problems that I cannot understand why exist, but they're fixed by invalidating the caches and restarting (from the file menu item). Because the code compiles fine, it seems that this is one of those cases, in which a cache entry somehow ends up, I'm not really sure what specifically happens, but essentially something that prevents it from working properly.
So invalidating the caches and restarting may issues like this, whether it's with Gradle or with Java/Kotlin/Scala/<insert language here>.
For flutter specific,
It won't throw an error. But if you don't want those Red letters then you can replace
GradleException
with
RuntimeException
Related
I am starting to learn flutter & by extension, dart.
However! every time I follow a tutorial & start a new project in vs code I have to go to the file called gradle.properties and add org.gradle.java.home=C:/Program Files/Java/jdk-11.0.9 or else I won't be able to run/debug!
Because I get an error saying I need java 11 while I'm using 1.8 which is TOTALLY not true because my java_home (& path) variable is set to java 11, which is the directory i add through the previously mentioned line of code.
Please, I do not know what to do, and googling is no longer helping as no result I'm finding is working. I need someone to tell me what to do to solve this... issue because I am sure something can be done once instead of repeating this process every time.
Note: I found on google people saying stuff like:
Set Gradle jdk path to java 11 in android studio
but I do not have that option.
Also, please note that I am still a beginner-level developer with little practical experience - Sorry if my question is, well, stupid.
attached images:
Gradle Error if gradle.properties not modified
gradle.properties file
my Android Studio settings
Android Studio settings found on the internet
~Have a nice day.
I had same problem after updating Flutter. Try to check your JAVA version java -version (update it, if it less than 8).
Then update Android SDK: https://stackoverflow.com/a/61434900/13506243
This helped me.
I can't run all of my flutter apps, because in the console appears everytime this error message:
Downloading Gradle Wrapper... 1,2s
Launching lib\main.dart on SM G960F in debug mode...
Running Gradle task 'assembleDebug'...
Finished with error: Unable to locate gradlew script. Please check that C:\Users\...\android\gradlew.bat exists or that C:\Users\...\android can be read.
I try to fix this problem more than ten hours and don't find a solution.
I will advise you to check your pc properly for unwanted programs. Something is preventing your pc from running the Gradle. I had the same issue only to realize that antivirus was installed on my pc alongside a cd burner that I just installed. Check for any antivirus that might be preventing Gradle from running.
I also faced the same error initially. While creating a flutter application from scratch I just ran the default flutter application which is a counter app in a flutter. I faced the same issue at first. If you are in this same context as described earlier the following could be the solution
1.Java 8 is more suitable for the flutter/android development. The next versions of java have some exceptions. I used the Java 14 and stuck at this issue for some time
The next could be the JAVA_HOME path in your environment variables. If it is not provided the set the JAVA_HOME path.
Run flutter --doctor and check the requirements if satisfied like Android SDK is updated or not, upgrade flutter if required. In some cases having good Internet connection also plays a role in this issue some times.
These are the major points to be satisfied in order to get rid of this error. Mostly this could be the a solution or part of it.
The error suggests that something is preventing gradle to run properly on your machine. Check whether you have any unwanted programs or anti-virus on your machine running that might be preventing gradle to run. If so, remove or stop those programs / anti-virus and try again.
After that, delete the .gradle folder located here C:\Users\yourPcName\.gradle containing the unfinished file and try again . It will work now .
You can also manually download Gradle and map it in Android studio , Learn more with this article here .
Warning, the gradle versions change quickly, so make sure you manually
downloaded the exact version that flutter wanted to download and the
download failed. Download the gradle here and then replace it in the
gradle folder.
C:\Users\yourPcName\.gradle\wrapper\dists\gradle-x.x.x-all
If it still doesn't work,
Try to run flutter --doctor
From a console window that has the Flutter directory in the path (see above), run the following command to see if there are any platform dependencies you need to complete the setup:
C:\src\flutter> : flutter doctor
This command checks your environment and displays a report of the status of your Flutter installation. Check the output carefully for other software you might need to install or further tasks to perform (shown in bold text).
You can learn more here :
If flutter doctor itself doesn't work, then know that flutter is not installed on your machine (or you forgot to add it to the environment
variable).
I also faced this problem and I made something to run my app on android
tried to open anything on android files and android studio ask me if I want to open for editing android file in android studio then click on it and it will open android project then click run enter image description here
My project uses these plugins:
OneSignal
GooglePlayServices
Adjust
Google Analytics
Unity IAP
Facebook SDK
Those plugins are used in almost every project.
But I am over field references count
This is my .aar file list
What should I do to decrease reference count?
So What should i do to decrease reference count ?
You have so many plugins with many functions/fields. There is a limit when building this from Unity's Editor and you have reached that limit.
To decrease reference count, you have to delete some these plugins but I am sure that you need them and deletion may not be the appropriate solution in this case.
The only way to actually get around this and build for Android at this moment is to export the Project as Android Project then build it with Android Studio. This removes the reference limit imposed by Unity's Editor.
EDIT
I forgot to mention that you have to enable multidex after exporting it out. Since many people go through this problem daily, I decided to add a thorough instruction on how to fix this problem by exporting it out and also how to fix it without exporting it.
FIX BY EXPORTING THE PROJECT
1A.Export the Unity Project as Android Project.
1B.Import into Android Studio:
If you get grade error when importing into Android Studio like the one below:
Error:org.gradle.api.internal.tasks.DefaultTaskInputs$TaskInputUnionFileCollection
cannot be cast to
org.gradle.api.internal.file.collections.DefaultConfigurableFileCollection
In the "dependencies" block which is in the "buildscript" block in the build.gradle file, change:
classpath 'com.android.tools.build.gradle.2.1.0'
to
classpath 'com.android.tools.build:gradle:2.2.3'
If you export the Project and still get the-same error, you need to manually enable multidex. Below is a simplified step to follow from Google's doc that will be shown to you in the error:
2.Add android:name="android.support.multidex.MultiDexApplication" > to the
application tag in the AndroidManifest.xml file.
3.Add compile 'com.android.support:multidex:1.0.1' to the "dependencies" block in the build.gradle file.
4.Add multiDexEnabled true to the "defaultConfig" block which is in the "android" block in the build.gradle file.
Build APK and see if it works. If the reference count error is gone, stop here.
5.Getting a GC overhead exception like the one below?
java.lang.OutOfMemoryError: GC overhead limit exceeded
Increase the heap size that will be used when performing dex operation. From this solution, add the following to the "android" block in the build.gradle file:
dexOptions {
javaMaxHeapSize "4g"
}
FIX WITHOUT EXPORTING THE PROJECT
Must have Unity 5.5 and above to do this:
1.Go to <UnityInstallationDirecory>\Editor\Data\PlaybackEngines\AndroidPlayer\Tools\GradleTemplates, Copy the mainTemplate.gradle file to your <ProjectName>Assets\Plugins\Android folder.
2.Go to <UnityInstallationDirecory>\Editor\Data\PlaybackEngines\AndroidPlayer\Apk, Copy the AndroidManifest.xml file to your <ProjectName>Assets\Plugins\Android
3.Open both the mainTemplate.gradle and AndroidManifest.xml file you just copied with Visual Studio then do the modification from the FIX BY EXPORTING THE PROJECT instruction above. Skip/Ignore step #1A and #1B. Just do steps from #2 to #5. That's it.
This is what the final mainTemplate.gradle should look like and this is what the final AndroidManifest.xml should look like. This is only for reference purposes. I suggest you don't use mine but instead follow the copy steps above to create yours because future Unity versions can come with different files. You want to make sure you use the latest one or you may have problems building it.
4.Build APK and see if it works:
--
If the reference count error is gone, stop here:
5.Getting an error like the one below?
Build Failure Release builds have to be signed when using Gradle
Just sign the apk from the Publishing Settings in the Build Settings. You can create new keystore or use an existing one.
6.Another error like below?
Error: Avoid hardcoding the debug mode; leaving it out allows debug
and release builds to automatically assign one [HardcodedDebugMode]
Remove android:debuggable="true"> from the AndroidManifest.xml file.
If this non exporting solution did not work for you then you have to
use the exporting solution.
IMO, The accepted answer isn't correct (or only partly correct). Exporting an Android studio will not "magically" fix this issue. Also, from my experience, the exported Android studio project does not always build right away and you have to fix lots of things before you can actually build it.
You are using lots of plugins and so you faced an Android limitation of not being able to reference more than 64k methods.
There are a few things you can try to solve this:
Delete some of these plugins, if possible (as already suggested in the accepted answer).
Use multidex. In the past this was only possible by exporting the project to Android studio and building it there. Starting with Unity 5.5 you can build your project using Gradle right from Unity. This means you can create a custom gradle file that configures your game to use Multidex. This doesn't reduce the method ref count, but it works around it by splitting your native Java count into multiple dex files.
Use ProGuard - since you can use Gradle from Unity, you can also define ProGuard to run and remove any code that is not used.
I recently changed over to Android Studio from Eclipse and when starting new projects with a blank activity template have come across the following message in my main layout xml file
I looked up SO and tried the following solutions:
*Raising the minSDK in the build.gradle file - it raised additional problems of missing styles
*Trying to update Android Studio - I was up-to-date even in the "Canary" setting
*Reducing the API level of the layout - when I went down to API 22, the image disappeared altogether.
In Eclipse, I would go to Properties/Android and see if anything needed to be updated, or go to Build Path to see if it looked OK.
What can I do here? Thanks:)
I have just found an answer on SO that worked for me. (I am sorry but I haven't figured out how to quote the question no.)
I also got this problem today,
Check your build.gradle file, do you use support design lib version
23.2, like
compile 'com.android.support:design:23.2.0' if so, change it to
version 23.1.0
compile 'com.android.support:design:23.1.0' then rebuild your
project... seems version 23.2 is still buggy
New to Android. I'm trying to build the HelloCompute sample code for API 17 with ADT v22.0.1 under Windows 7. I do File:New Project:Android Sample Project, and select HelloCompute. In the Package Explorer I see HelloCompute.java and mono.rs in src under com.example.android.rs.hellocompute. However, I don't see any reflected layer code under gen, and I get the error "ScriptC_mono cannot be resolved to a type". I have tried re-installing eclipse / adt, and re-installing the sample code.
Is there some manual step I need to perform to generate the reflected layer?
Thanks.
I ran into a similar problem.
I got around it by running llvm-rs-cc on mono.rs and generating the ScriptC_mono.java file. Eclipse then picks up this source and compiles everything successfully.
I do not know yet whether is there a way of telling eclipse to do it automatically.
The latest ADT does have a problem in generating RenderScript code as part of the build process, so you need to do this step manually right now (or look at other threads suggesting workarounds). Hopefully the upcoming ADT will actually fix this issue so that everything gets created automatically.
Had the same problem.
Win 7 64bit.
Eclipse 4.2.2.
Upgraded to:
SDK Tools: 22.0.5.
Platform-tools: 18.0.1.
Build-tols: 18.0.1.
Problem solved.
Renderscript compilation was broken in ADT 22.0.1. Fixed for non-Windows platforms on 22.0.4. Fixed for Windows platform on 22.0.5.