Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to solve the problem that Android Studio can't execute the main method of Java class

2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)05/31 Report--

This article introduces the relevant knowledge of "Android Studio can not implement the main method of Java class". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Environment

Android studio version: 3.6.1

Gradle version: 5.6.4

Gradle plug-in version: 3.6.1

Error prompt

11:41:35 PM: Executing task 'TxtUtil.main ()'...

Executing tasks: [TxtUtil.main ()] in project / Users/tinytongtong/Documents/workspace/as/self/BlogDemo

FAILURE: Build failed with an exception.

* Where:

Initialization script'/ private/var/folders/qw/8_p1t59142d0xntgn799rt1c0000gn/T/TxtUtil_main__.gradle' line: 20

* What went wrong:

A problem occurred configuring project': app'.

Could not create task': app:TxtUtil.main ()'.

> SourceSet with name 'main' not found.

* Try:

Run with-- stacktrace option to get the stack trace. Run with-info or-debug option to get more log output. Run with-- scan to get full insights.

* Get more help at https://help.gradle.org

Deprecated Gradle features were used in this build, making it incompatible with Gradle 6.0.

Use'--warning-mode all' to show the individual deprecation warnings.

See https://docs.gradle.org/5.6.4/userguide/command_line_interface.html#sec:command_line_warnings

BUILD FAILED in 207ms

11:41:35 PM: Task execution finished 'TxtUtil.main ()'.

Solution:

Option 1: temporary alternatives

Run "XXX.main ()" with Coverage

Plan 2: modify the .idea / gradle.xml file

Android Studio uses gradle as the build tool, so it all boils down to gradle configuration. I first find a project that has no problem, then open the newly created project and compare their gradle configuration. After comparison and attempt, it is found that the .idea / gradle.xml file is different internally, and it is effective to modify it with reference to the old project.

Idea/gradle.xml of the old project:

...

Idea/gradle.xml of the new project:

After comparison, it is found that this line of configuration is missing under the label of the new project, and then this line of configuration is added to the new project, and the running code is found to be successful.

According to the literal meaning of the configuration, this setting means that gradle is not delegated to build. The reality is that after adding this line of configuration, jvm executes the main method of the Java class, rather than gradle as a task.

Knowledge point supplement, reference method

Android Studio 3.0 cannot run the solution of the Java code main () method

After upgrading Android Studio to 3. 0, it is found that grandle will report an error when running the main () method in Java code.

Solution:

Open the file marked in the following illustration under the project directory:

Add to the file after opening the file

Android.enableAapt2=false

Finally, synchronize OK!

This is the end of the content of "Android Studio can't execute the main method of the Java class". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report