📜 ⬆️ ⬇️

Methods of treating various errors in Android Studio during project development

Today I would like to share my analysis and ways of treating various errors when developing my product in Android Studio. Personally, I have repeatedly encountered various problems and errors when compiling and / or testing a mobile application. This process is always monotonous and in 99% of cases it is always necessary to spend n-amount of time for its elimination. Even when you have already encountered this problem, you still go to the search engine and remember how to solve this or that situation.

I made a file for myself, in which I noticed the most frequent mistakes - after spending a few hours on it and listed the most popular mistakes (I plan to just memorize them later) to shorten my time later.

So, I will start in order from the most common problem and will continue to list them as they appear:

1) If the underlined red code, where resources are used: R. - try (but probably will not help): Build -> Clean Project.
')
In principle, on Build -> Clean Project you can not lose time, and the best thing is to switch to the Project on the left, open the .idea directory, then the libraries directory and delete all the contents from it. Then click the Sync Project button. And then (if everything is still red, but most likely everything will be ok) Build -> Clean Project.

image

2) After a sudden shutdown of a computer, after a restart, all the code may be red in all projects. Before this, there may be an error: Unable to create Debug Bridge: Unable to start adb server: There are three solutions - the first one helped, the second one did not (but maybe for a different case), and the third one did not try:

a) File - Invalidate Caches / Restart - Invalidate and Restart

b) Close the studio. At the root of the project folder, delete the .iml file (s) and the .idea folder. Restart the studio and import the project.

c) Press Ctrl-Alt-O and start import optimization.

By the way, adb server can be checked for version (and working capacity) and then restarted:

adb version adb kill-server adb start-server 

3) If Android Studio gives an error like this: Error: Execution failed for task ': app: dexDebug' ...

Decision:

It is necessary to switch on the left to the Project option, find and delete the build folder which lies in the app folder, i.e. on the app / build path. Then rebuild the whole project again: Build -> Rebuild Project.

The same solution if the error type: "I can not delete (create) a folder or file" and the path is specified, which leads to app / build. Also delete the build folder and rebuild the project.



4) The error message mentions heap - virtual memory. And the error is usually caused by its lack, i.e. inability to get the requested amount. Therefore, this requested amount should be reduced, i.e. rewrite the default value (usually 2048 MB which can be changed in the settings) to less than 1024 MB.

In the project file gradle.properties we write:

org.gradle.jvmargs = -Xmx1024m



5) Android Studio will come with the following error: Plugin is too old, please update to a more recent version, or set ANDROID_DAILY_OVERRIDE environment variable to "83648b99316049d63656d7276cb19cc7e95d70a5"

Possible reasons (except for the need to regularly update the SDK):

a) The loaded project was compiled using the already incompatible old gradle plugin. In this case, you need to find and connect this older plugin in your build.gradle project. those. try older versions, for example: 1.1.3 (often it is 1.1.x that suits).

com.android.tools.build:gradle:1.1.3

Find all versions here .

b) If the beta version of the plugin is used in the build.gradle of the project, this means that it has expired. You can also see the latest releases (production and beta) here :

6) Sometimes when connecting third-party libraries, some files (usually associated with licensing) can be duplicated. The message will contain something that contains the words: duplicate files. Solution - you need to look in the error message or in the documentation of the connected third-party library - which files have become redundant, and list them in the build.gradle module to exclude from the build.

This is done in the packagingOptions directive (which, in turn, is in the android directive).

For example, when connecting the Firebase library (cloud back-end service), if such an error occurs in the build.gradle module (not the project), we add packagingOptions to android (the directives that already exist there are left) like this:

 android { ... packagingOptions { exclude 'META-INF/LICENSE' exclude 'META-INF/LICENSE-FIREBASE.txt' exclude 'META-INF/NOTICE' } } 



PS: I think this article was helpful. If you have any private problems when working with projects in Android Studio, I’ll be happy to hear them. As for me, 6 problematic causes that I listed above are 99% of all project crashes. Of course, if the problem is not related to your personal code.

Source: https://habr.com/ru/post/270479/


All Articles