質問

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
役に立ちましたか?

解決

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

他のヒント

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

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top