I am trying to convert our Android application to a gradle build. I have the project and it\'s libraries building successfully. I am now trying to create separate apks fo
I did all the things in the answers but still didn't work. I solved my problem by changing the package name in the manifest.xml
file which still hadn't been updated :
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.example.android">
I had similar problem related to build types being setup using .initWith(someotherbuildtype), BuildConfig was not being created properly. I had to switch to the parent build variant and build that first, then the build types that initWith the parent built fine.
Here is what fixed this for me:
File -> Invalidate Caches/Restart... -> Invalidate and Restart
Please, be sure that you are building "dev" or "prod" variant. There is no BuildConfig definition in default "debug" and "release" variant. In Android Studio, you can select current variant in bottom left corner:
To simplify your build.gradle file, you can define:
buildTypes {
debug {
buildConfigField "String", "URL_SEARCH", "\"https://dev-search.example.com\""
// etc.
}
release {
buildConfigField "String", "URL_SEARCH", "\"https://search.example.com\""
// etc.
}
}
and then just use default "debug" and "release" variants.
At last, delete semicolon (sign: ';') from the value of buildConfigField parameter.