0

I want to create the following project structure with gradle

FlavorA
     java
        sources
FlavorB
     java
        sources
FlavorC
     java
        sources
main
     java
        sources
commonCodeWithFlavorAAndB
      java
        sources
commonCodeWithFlavorAAndC
      java
        sources

now I created this project structure, and defined the sourceSet srcDirs in build.gradle

however, when i try to run flavorA it says a class from commonCodeWithFlavorAAndC is missing to run A

How can I fix it?

Lena Bru
  • 13,521
  • 11
  • 61
  • 126

2 Answers2

1

When you create different flavors it has two aspects to deal with

  1. res folder

  2. java files

    • With res folder, you can actually have same file in main, FlavorA ,... Android will automatically MERGE it.

    • With java files, the classes canNOT be merged. It can only be replaced.

See this for better understanding

https://stackoverflow.com/a/23710180/1852441

Ie. In order to override a class called Activity1.java (for instance), you will have to remove it from main folder and provide each flavor with Activity1.java.

That is why the compiler says it is missing a class.

Community
  • 1
  • 1
  • This answer does not help me unfortunately, I did remove the file from main, I have files in FlavorA and commonAAndC, but it says the file in commonAAndC is missing – Lena Bru Jul 15 '16 at 06:13
0

The problem was caused by an error in refactoring. When I split the files into different implementations, it for some reason changed the package name of the given file in the FlavorAAndC folder, even though it was on the same path folderx/foldery/file the top line of "package" said "folderx.foldery.folderz?!.file"

Lena Bru
  • 13,521
  • 11
  • 61
  • 126