简体   繁体   English

从Android Studio项目中删除Android(应用程序或lib)模块需要在每次项目启动时将项目与gradle文件同步

[英]Removing Android (app or lib) module from Android Studio project requires syncing project with gradle files at every project startup

Following the guides here on stack overflow I was able to create a pure Java program using Android studio. 按照堆栈溢出的指导,我能够使用Android Studio创建纯Java程序。

Here's what I did: 这是我所做的:

  1. I created a new project with no activity 我创建了一个没有活动的新项目
  2. I added a java library module and created a main method inside the added java library class 我添加了一个Java库模块,并在添加的Java库类中创建了main方法
  3. Through “edit configuration” I configured Android Studio to start the class inside the Java library 通过“编辑配置”,我配置了Android Studio以启动Java库中的类

Since I wanted to create a pure Java program I removed the app module from the project structure and deleted the app folder as well. 由于我想创建一个纯Java程序,因此我从项目结构中删除了app模块,并删除了app文件夹。

The problem is that, after removing the app module, every time I start the project I need to sync project with gradle files to show the java library folder. 问题是,在删除应用程序模块后,每次启动项目时,我都需要将项目与gradle文件同步以显示java库文件夹。

If I do not sync project with gradle files the java library folder is hidden and all other folders and files in the project are highlighted with a yellow color. 如果我不将项目与Gradle文件同步,则Java库文件夹将被隐藏,项目中的所有其他文件夹和文件将以黄色突出显示。

Can you tell me if it it is possible to avoid manual syncing project with gradle files at every project startup? 您能否告诉我是否可以避免在每次项目启动时手动将项目与Gradle文件同步?

As far as I can tell, this problem is the same as this defect I raised with Google: Task graph, syncing is incomplete for Java modules when running unit tests from UI gesture if there is no Android module 据我所知,这个问题与我在Google上提出的缺陷相同: 任务图,如果没有Android模块,则通过UI手势运行单元测试时Java模块的同步是不完整的

This problem doesn't just cause this syncing issue. 此问题不仅会导致此同步问题。 It also messes with the task graph such that Java unit tests will not be rebuilt prior to running them, leading to strange errors about missing classes or old test classes being run for days or weeks. 它还使任务图混乱,以至于在运行Java单元测试之前不会对其进行重新构建,从而导致有关丢失类运行数天或数周的旧测试类的奇怪错误。

I have found no workaround, other than committing a dummy Android library module parallel to the pure Java modules. 除了提交与纯Java模块并行的虚拟Android库模块外,我没有找到其他解决方法。 The problem with having to force a manual sync should be fixed in Android Studio 3.3. 必须强制进行手动同步的问题应在Android Studio 3.3中修复。

Also, with 3.3 the task graph seems to be fixed, but invoking Run 'All Tests' on a clean build will still fail the first time. 同样,在3.3版中,任务图似乎已修复,但是在干净的版本上调用“运行所有测试”仍将首次失败。 It is making the classes, though, so if you invoke that gesture immediately it seems to work. 但是,它正在制作类,因此,如果立即调用该手势,它似乎可以工作。 This may be a different defect. 这可能是一个不同的缺陷。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM