英文:
Android Studio-- conditionally compile a class in or not?
问题
可以告诉Android Studio在编译时完全忽略单个类文件吗?我有几个实用类,都在一个文件夹中,会编译到每个项目中。其中一个类不符合Google Family政策,因此我希望在编译时跳过该类,但仅针对特定的应用程序。
在C++中,通过简单的定义,这将非常容易做到。在Java中是否有一种方法可以实现这一点?再次强调,我希望完全忽略整个文件,而不仅仅是其中的一部分。
英文:
Is it possible to tell Android Studio to ignore a single class file completely when compiling? I have several utility classes, all in one folder, that get compiled into each project. One of the classes is non-compliant with a Google Family policy, so I want to skip that one when I compile, but ONLY for that particular app.
In C++ this would be very easy to do with a simple define. Is there a way to do it with Java? Again, I want to ignore the whole file completely, not just parts of it.
答案1
得分: 1
好的,以下是已翻译的部分:
"Okay, s I'm answering this just so it exists out there with an answer.
No, there appears to be no way to do this in Android Studio. The proguard method will keep the class file from being generated, but it will still try to compile the java, thus causing compile errors if you have something missing that the class expects to be there.
I "solved" this problem by just commenting out the entire java file for the compile for the specific app in question. It just has to be commented and uncommented for different compiles. No streamlined solution exists as of June, 2023."
英文:
Okay, s I'm answering this just so it exists out there with an answer.
No, there appears to be no way to do this in Android Studio. The proguard method will keep the class file from being generated, but it will still try to compile the java, thus causing compile errors if you have something missing that the class expects to be there.
I "solved" this problem by just commenting out the entire java file for the compile for the specific app in question. It just has to be commented and uncommented for different compiles. No streamlined solution exists as of June, 2023.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论