【问题标题】:Is there a way to programmatically distinguish between IntelliJ IDEA and Android Studio [duplicate]有没有办法以编程方式区分 IntelliJ IDEA 和 Android Studio [重复]
【发布时间】:2021-10-28 18:56:44
【问题描述】:

我想包含 settings.gradle.kts 文件的不同部分,具体取决于项目是使用 IntelliJ IDEA 还是 Android Studio 编译的。

出于我的目的,我只需要知道项目是否使用 Android Studio 编译,因为项目的某些特定于移动设备的模块只能使用 Android Studio 编译。

由于这些模块在设置 gradle kotlin 脚本文件中是有区别的,我希望找到一个解决方案,其中一个简单的 if 相应地包含这些模块。到目前为止,我在 IDEA 工作时一直在注释掉相关模块。

【问题讨论】:

标签: android-studio kotlin gradle intellij-idea gradle-kts


【解决方案1】:

在 Android Studio/IntelliJ IDEA 中设置了两个相关属性:

  • idea.paths.selector,在默认安装中具有诸如“AndroidStudioPreview2021.1”或“IntelliJIdea2021.2”之类的值,因此如果您需要知道它是不是,可以使用它:
val pathSelector: String? = System.getProperty("idea.paths.selector")
if(pathSelector == null) // Some other IDE or none
else if(pathSelector.startsWith("AndroidStudio"))
// Do Android Studio specific things
else if(pathSelector.startsWith("IntelliJIdea"))
// Do IntelliJ IDEA specific things
else // Some other Jetbrains IDE
  • idea.platform.prefix,似乎只为 Android Studio 设置,值为“AndroidStudio”,所以它适用于我的情况:
if(System.getProperty("idea.platform.prefix") == "AndroidStudio")
   // Do Android Studio specific things
else // Any other IDE or none

感谢@Konstantin Annikov 通知我另一个类似的问题,该问题从未完全回答但在正确的轨道上(使用属性)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-03-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-04-02
    • 2021-08-28
    相关资源
    最近更新 更多