Android Studio – 有条件地编译一个类或不编译?

huangapple go评论70阅读模式
英文:

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.

huangapple
  • 本文由 发表于 2023年6月8日 22:31:18
  • 转载请务必保留本文链接:https://go.coder-hub.com/76432920.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定