【问题标题】:How to access .java files from a directory outside of a package in android-studio?如何从 android-studio 中包外的目录访问 .java 文件?
【发布时间】:2015-02-23 19:01:49
【问题描述】:

我尝试解决这个问题已经好几个小时了,但在互联网上没有找到解决方案。 我的项目如下所示:

我想访问de.MayerhoferSimon.Vertretungsplan 包中标记目录中的文件。 (是的,我知道包应该是小写的。)

这可能吗?如果可以,怎么做?

我在:app 模块的 .gradle 文件中尝试了一些依赖项,但没有任何效果。

【问题讨论】:

  • Java 包不能具有该名称。它们应该是文件夹,例如de/MayerhoferSimon/Vertretungsplan(您可以查看com 文件夹以了解我在说什么)。然后在项目设置中添加de文件夹作为源代码。
  • 问题是:这个目录是一个库,我把它添加为一个git子模块
  • 那么它应该被打包成一个JAR或者一个单独的模块并链接到类路径中。
  • @m0skit0 包de.MayerhoferSimon.Vertretungsplan 没问题。 linter 错误只是因为其他文件。
  • 是的,我知道。我正是这个意思。最好将它放在 JAR 或单独的模块中并链接到类路径,而不是复制到当前模块中。无论如何,如果您在项目设置中将该文件夹标记为源代码文件夹,它应该可以工作。

标签: android android-studio gradle build.gradle


【解决方案1】:

在这种情况下,您应该为您的 webuntisaccessor 代码创建一个库模块,而不是将其放在 libs 文件夹中。

root
  settings.gradle
  app
    build.gradle
  webuntisaccessor
    src
      main    
        java
    build.gradle

settings.gradle:

include ':webuntisaccessor' , ':app'

webuntisaccessor/build.gradle

apply plugin: 'com.android.library'

app/build.gradle 中添加:

dependencies {
    compile project(':webuntisaccessor')
}

【讨论】:

    猜你喜欢
    • 2017-01-06
    • 2013-07-27
    • 1970-01-01
    • 2018-04-03
    • 1970-01-01
    • 2013-06-21
    • 2016-10-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多