How to add a linked source folder in Android Studio?

前端 未结 6 1799
野的像风
野的像风 2020-11-28 05:38

In Eclipse I can add a source folder to my android project as a \"linked source folder\". How do I achieve the same thing in Android Studio?

Or is it possible to ad

相关标签:
6条回答
  • 2020-11-28 06:06

    Just in case anyone is interested, heres a complete Java module gradle file that correctly generates and references the built artefacts within an Android multi module application

    buildscript {
        repositories {
            maven {
                url "https://plugins.gradle.org/m2/"
            }
        }
        dependencies {
            classpath "net.ltgt.gradle:gradle-apt-plugin:0.15"
        }
    }
    
    apply plugin: "net.ltgt.apt"
    apply plugin: "java-library"
    apply plugin: "idea"
    
    idea {
        module {
            sourceDirs += file("$buildDir/generated/source/apt/main")
            testSourceDirs += file("$buildDir/generated/source/apt/test")
        }
    }
    
    dependencies {
    
        // Dagger 2 and Compiler
        compile "com.google.dagger:dagger:2.15"
        apt "com.google.dagger:dagger-compiler:2.15"
        compile "com.google.guava:guava:24.1-jre"
    
    }
    
    sourceCompatibility = "1.8"
    targetCompatibility = "1.8"
    
    0 讨论(0)
  • 2020-11-28 06:07

    in your build.gradle add the following to the end of the android node

    android {
        ....
        ....
    
        sourceSets {
            main.java.srcDirs += 'src/main/<YOUR DIRECTORY>'
        }
    
    }
    
    0 讨论(0)
  • 2020-11-28 06:13

    While sourceSets allows you to include entire directory structures, there's no way to exclude parts of it in Android Studio (as of version 1.2), as described here: Android Studio Exclude Class from build?

    Until Android Studio gets updated to support include/exclude directives for Android sources, Symlinks work quite well. If you're using Windows, native tools such as junction or mklink can accomplish the equivalent of Un*x symlinks. CygWin can also create these with a little coersion. See: Git Symlinks in Windows and How to make symbolic link with cygwin in Windows 7

    0 讨论(0)
  • 2020-11-28 06:13

    If you're not using gradle (creating a project from an APK, for instance), this can be done through the Android Studio UI (as of version 3.3.2):

    • Right-click the project root directory, pick Open Module Settings
    • Hit the + Add Content Root button (center right)
    • Add your path and hit OK

    In my experience (with native code), as long as your .so's are built with debug symbols and from the same absolute paths, breakpoints added in source files will be automatically recognized.

    0 讨论(0)
  • 2020-11-28 06:29

    The right answer is:

    android {
        ....
        ....
    
        sourceSets {
            main.java.srcDirs += 'src/main/<YOUR DIRECTORY>'
        }
    }
    

    Furthermore, if your external source directory is not under src/main, you could use a relative path like this:

    sourceSets {
        main.java.srcDirs += 'src/main/../../../<YOUR DIRECTORY>'
    }
    
    0 讨论(0)
  • 2020-11-28 06:29

    You can add a source folder to the build script and then sync. Look for sourceSets in the documentation here: http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Basic-Project

    I haven't found a good way of adding test source folders. I have manually added the source to the .iml file. Of course this means it will go away everytime the build script is synched.

    0 讨论(0)
提交回复
热议问题