문제

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