BuildConfig not getting created correctly (Gradle Android)

前端 未结 10 702
一生所求
一生所求 2020-12-14 14:07

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

相关标签:
10条回答
  • 2020-12-14 14:32

    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">
    
    0 讨论(0)
  • 2020-12-14 14:38

    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.

    0 讨论(0)
  • 2020-12-14 14:39

    Here is what fixed this for me:

    File -> Invalidate Caches/Restart... -> Invalidate and Restart 
    
    0 讨论(0)
  • 2020-12-14 14:41

    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:

    Build Variants

    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.

    0 讨论(0)
提交回复
热议问题