Is it possible in Android Studio to launch the main() method of a simple java-class that contains only references to the standard java classes without compiling the entire Android project.
|
2 answers
Yes you can. To do this, you need to specify in the IDE, but rather to give new settings for your debugger, so that it understands which part to compile. In fact, everything is much simpler.
Create a java class:
We write the main method
As usual, the IDE immediately recognizes the starting point.
public class HelloFromMainJava { public static void main(String... args){ System.out.println("HelloFromAndroidStudio ☺!"); } } You can run from the panel, or right-click the mouse, or just a combination of keys as in the screenshot. 
Total:
Do not forget on the panel, above, switch back to your project. Good luck.
- oneThank. Strangely, yesterday I did the same thing, but System.out.println did not give out anything and compiled the whole project. Now everything worked with your light hand)) - iramm
- oneIsn't the whole project compiled in this case? - post_zeew
- In this case, gradle will rebuild everything according to the standard, if you want to completely ignore other classes, then you need to reconfigure the build gradle, as I remember, you can specify the exact path in the srcSet. In fact, there are many options here, will depend on your desire. From my own experience, I open IntelliJ IDEA separately, so for simpler, faster and more convenient, and all the additional utilities that I might not even use in the project, I write and test there. You can make a separate module by the way, if you need exactly Android classes, also an interesting option. - Shwarz Andrei
|
To edit and compile standard Java classes, download a development environment, such as NetBeans . Convenient and fast.
- I already started a class that interests me in Intellij Idea. The problem was in the toString () method. Inside the Android project when using this class, the Cyrillic alphabet looked unrecognizable. When launched into Idea, Cyrillic characters looked correct. The reasons for this problem have not yet been clarified. - iramm
- I would not mind including everything in string.xml, but is it possible for messages like "Tomorrow, October 2, 2016 ..." What you advise, I will try in the near future. - iramm
- @pavlofff Thanks for the link. Looks like I'm wrong. And in this case you can also do with string resources. - iramm
|

mainmethod as mentioned above and execute it on the fly in the Android application itself? - Streletz