Android gradle: Sharing dependencies between product flavors

前端 未结 2 1200
别那么骄傲
别那么骄傲 2021-01-14 23:47

I have 3 product flavors (flavor1, flavor2, flavor3) in my app. flavor1 and flavor2 share some of the dependencies related to ads.

Is there a way to bundle the ad r

2条回答
  •  伪装坚强ぢ
    2021-01-15 00:19

    This is what we did to share directories between flavors:

    sourceSets {
        main {
          java.srcDirs = ['src/main/java']
          res.srcDirs = ['src/main/res']
          assets.srcDirs = ['src/main/assets']
        }
        production {
          java.srcDirs = ['src/main/java', 'src/shared/java']
          res.srcDirs = ['src/main/res', 'src/shared/res']
          assets.srcDirs = ['src/main/assets', 'src/shared/assets']
        }
        logger {
          java.srcDirs = ['src/main/java', 'src/shared/java', 'src/mock/java']
          res.srcDirs = ['src/main/res', 'src/shared/res']
          assets.srcDirs = ['src/main/assets', 'src/shared/assets']
        }
        nowav {
          java.srcDirs = ['src/main/java', 'src/nowav/java', 'src/mock/java']
          res.srcDirs = ['src/main/res', 'src/nowav/res']
          assets.srcDirs = ['src/main/assets', 'src/nowav/assets']
        }
    }
    

提交回复
热议问题