How to access .java files from a directory outside

2019-09-04 07:02发布

问题:

I try to solve this problem for hours now and didn't find a solution on the internet. my project looks like this:

I want to access the files in the marked directory in the de.MayerhoferSimon.Vertretungsplan package. (yes, I know packages should be lowercase.)

Is this possible and when yes, how?

I tried some things with the dependencies in the .gradle file of the :app module but nothing worked.

回答1:

In this case you should create a library module for your webuntisaccessor code instead of putting this in the libs folder.

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

In settings.gradle:

include ':webuntisaccessor' , ':app'

In webuntisaccessor/build.gradle

apply plugin: 'com.android.library'

In app/build.gradle add:

dependencies {
    compile project(':webuntisaccessor')
}