Pregunta

My Android project has a lot of different Build Variants and each variant has its own debug and release.

I have a Constants.java file which contains urls but are different for release and debug. Does somebody know how to make my constants file work with all flavours but different for debug and release?

My project structure is something like this:

├── main
│   ├── AndroidManifest.xml
│   ├── ic_launcher-web.png
│   ├── java
│   │   └── com
│   │       └── companyname
│   │           └── appname
│   │               └── MainActivity.java
│   └── res
│       ├── drawable-hdpi
│       │   └── ic_launcher.png
│       ├── drawable-mdpi
│       │   └── ic_launcher.png
│       ├── drawable-xhdpi
│       │   └── ic_launcher.png
│       ├── drawable-xxhdpi
│       │   └── ic_launcher.png
│       ├── layout
│       │   └── activity_main.xml
│       ├── menu
│       │   └── main.xml
│       ├── values
│       │   ├── dimens.xml
│       │   ├── strings.xml
│       │   └── styles.xml
│       ├── values-v11
│       │   └── styles.xml
│       └── values-v14
│           └── styles.xml
├── flavour1
│   ├── java
│   │   └── com
│   │       └── companyname
│   │           └── appname
│                   └── x.java
└── flavour2
    ├── java
    │   └── com
    │       └── companyname
    │           └── appname
    │               └── x.java
    └── res
        ├── drawable-hdpi
        │   └── ic_launcher.png
        ├── drawable-mdpi
        │   └── ic_launcher.png
        ├── drawable-xhdpi
        │   └── ic_launcher.png
        ├── drawable-xxhdpi
        │   └── ic_launcher.png
        └── values
            └── string.xml
¿Fue útil?

Solución

fixed and of course it was easy as hell. Just create a directory named "debug" or "release" in "src"

Otros consejos

You can keep the code and resources separate for debug and release variant by using this directory structure:

enter image description here

You can replace the MainActivity with your Constants file and have it work separately for debug and release variant

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top