久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

BuildConfig 未正確創(chuàng)建(Gradle Android)

BuildConfig not getting created correctly (Gradle Android)(BuildConfig 未正確創(chuàng)建(Gradle Android))
本文介紹了BuildConfig 未正確創(chuàng)建(Gradle Android)的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!

問(wèn)題描述

我正在嘗試將我們的 Android 應(yīng)用程序轉(zhuǎn)換為 gradle 版本.我有這個(gè)項(xiàng)目,它的圖書館建設(shè)成功.我現(xiàn)在正在嘗試為我們的各種環(huán)境創(chuàng)建單獨(dú)的 apk(dev/test/prod 對(duì)它們使用的 restful 服務(wù)有不同的 url).

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 for our various environments (dev/test/prod have different urls for the restful services they consume).

在四處搜索時(shí),我認(rèn)為最好的方法是為每個(gè)環(huán)境制作不同的 BuildConfig.這是我嘗試過(guò)的:

In searching around, the best way that I feel to do this is with making different BuildConfig for each environment. This is what I tried:

import java.util.regex.Pattern

buildscript {
    repositories {
        mavenCentral()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:+'
    }
}

apply plugin: 'android'

task('increaseVersionCode') << {
    def manifestFile = file("AndroidManifest.xml")
    def pattern = Pattern.compile("versionCode="(\d+)"")
    def manifestText = manifestFile.getText()
    def matcher = pattern.matcher(manifestText)
    matcher.find()
    def versionCode = Integer.parseInt(matcher.group(1))
    def manifestContent = matcher.replaceAll("versionCode="" + ++versionCode + """)
    manifestFile.write(manifestContent)
}

tasks.whenTaskAdded { task ->
    if (task.name == 'generateReleaseBuildConfig') {
        task.dependsOn 'increaseVersionCode'
    }
}

dependencies {
    compile 'com.android.support:support-v4:19.0.0' 
    compile files('libs/commons-io-2.4.jar',
                  'libs/google-play-services.jar',
                  'libs/gson-2.2.4.jar',
                  'libs/universal-image-loader-1.8.6.jar',
                  'libs/wakeful-1.0.1.jar')
    compile project(':pulltorefresh_lib')
    compile project(':edgeeffect_lib')
    compile project(':viewpagerindicator_lib')        
}

android {
    buildToolsVersion "18.1.1"
    compileSdkVersion "Google Inc.:Google APIs:18"

    defaultConfig { 
       minSdkVersion 14
       targetSdkVersion 18
    }

    buildTypes {
        debug {
            packageNameSuffix ".debug"
        }
        dev.initWith(buildTypes.debug)
        dev {
            buildConfigField "String", "URL_SEARCH", ""https://dev-search.example.com";"
            buildConfigField "String", "URL_CONNECT", ""https://dev-connect.example.com";"
            buildConfigField "String", "URL_SVC_NEWSLIST", ""https://dev-mobilenews.example.com/newslist";"
            buildConfigField "String", "URL_SVC_NEWSDETAIL", ""https://dev-mobilenews.example.com/newsdetail";"
            buildConfigField "String", "URL_SVC_REGISTERENDPOINTS", ""https://dev-mobilenews.example.com/registerendpoints";"
        }
        prod.initWith(buildTypes.release)
        prod {
            buildConfigField "String", "URL_SEARCH", ""https://search.example.com";"
            buildConfigField "String", "URL_CONNECT", ""https://connect.example.com";"
            buildConfigField "String", "URL_SVC_NEWSLIST", ""https://mobilenews.example.com/newslist";"
            buildConfigField "String", "URL_SVC_NEWSDETAIL", ""https://mobilenews.example.com/newsdetail";"
            buildConfigField "String", "URL_SVC_REGISTERENDPOINTS", ""https://mobilenews.pdc-np-cf.lmig.com/registerendpoints";"          
        }
    }

    sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
            java.srcDirs = ['src']
            resources.srcDirs = ['src']
            res.srcDirs = ['res']
            assets.srcDirs = ['assets']
        }
    }
}

問(wèn)題是我的 BuildConfig.java 似乎沒(méi)有注入靜態(tài)變量,因此我收到類似以下的錯(cuò)誤:

The problem is that my BuildConfig.java doesn't seem to get the static variables injected, therefore I get errors similar to:

/Users/path/to/project/MainActivity.java:348: error: cannot find symbol
            startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(BuildConfig.URL_SEARCH)));
                                                                              ^
  symbol:   variable URL_SEARCH
  location: class BuildConfig
/Users/path/to/project/MainActivity.java:359: error: cannot find symbol
            startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(BuildConfig.URL_CONNECT)));
                                                                              ^
  symbol:   variable URL_CONNECT
  location: class BuildConfig
/Users/path/to/project/MainActivity.java:600: error: cannot find symbol
            HttpPost httpPost = new HttpPost(BuildConfig.URL_SVC_REGISTERENDPOINTS);
                                                        ^
  symbol:   variable URL_SVC_REGISTERENDPOINTS
  location: class BuildConfig
/Users/path/to/project/service/AlarmNotificationService.java:145: error: cannot find symbol
        String requestUrl = BuildConfig.URL_SVC_NEWSLIST + "?"
                                       ^
  symbol:   variable URL_SVC_NEWSLIST
  location: class BuildConfig
/Users/path/to/project/service/NewsService.java:240: error: cannot find symbol
        String requestUrl = BuildConfig.URL_SVC_NEWSLIST + "?"
                                       ^
  symbol:   variable URL_SVC_NEWSLIST
  location: class BuildConfig
/Users/path/to/project/service/NewsService.java:530: error: cannot find symbol
            HttpPost httpPost = new HttpPost(BuildConfig.URL_SVC_NEWSDETAIL);
                                                        ^
  symbol:   variable URL_SVC_NEWSDETAIL
  location: class BuildConfig
6 errors

我的 build/source/buildConfig/debug/com/.../BuildConfig.java 文件包含:

My build/source/buildConfig/debug/com/.../BuildConfig.java file contains:

/**
 * Automatically generated file. DO NOT MODIFY
 */
package com....;

public final class BuildConfig {
  public static final boolean DEBUG = Boolean.parseBoolean("true");
  public static final String PACKAGE_NAME = "com.....debug";
  public static final String BUILD_TYPE = "debug";
  public static final String FLAVOR = "";
  public static final int VERSION_CODE = 5;
}

我做錯(cuò)了什么?

推薦答案

請(qǐng)確保您正在構(gòu)建dev"或prod"變體.默認(rèn)的調(diào)試"和發(fā)布"變體中沒(méi)有 BuildConfig 定義.在 Android Studio 中,您可以在左下角選擇當(dāng)前變體:

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:

為了簡(jiǎn)化您的 build.gradle 文件,您可以定義:

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.      
    }
}

然后只使用默認(rèn)的調(diào)試"和發(fā)布"變體.

and then just use default "debug" and "release" variants.

最后,從 buildConfigField 參數(shù)的值中刪除分號(hào)(符號(hào):';').

At last, delete semicolon (sign: ';') from the value of buildConfigField parameter.

這篇關(guān)于BuildConfig 未正確創(chuàng)建(Gradle Android)的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來(lái)源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問(wèn)題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

IncompatibleClassChangeError after updating to Android Build Tools 25.1.6 GCM / FCM(更新到 Android Build Tools 25.1.6 GCM/FCM 后出現(xiàn) IncompatibleClassChangeError)
How to get current flavor in gradle(如何在 gradle 中獲取當(dāng)前風(fēng)味)
How to fix quot;unexpected element lt;queriesgt; found in lt;manifestgt;quot; error?(如何修復(fù)“意外元素lt;查詢gt;在“清單中找到錯(cuò)誤?)
Multi flavor app based on multi flavor library in Android Gradle(基于 Android Gradle 中多風(fēng)味庫(kù)的多風(fēng)味應(yīng)用)
Android dependency has different version for the compile and runtime(Android 依賴在編譯和運(yùn)行時(shí)有不同的版本)
Transitive dependencies for local aar library(本地 aar 庫(kù)的傳遞依賴)
主站蜘蛛池模板: 久久精品中文字幕 | 国产精品a免费一区久久电影 | 伊人久久免费 | 一区观看| 亚洲免费精品一区 | 国产视频三级 | 一区二区免费看 | 国精产品一区二区三区 | 日韩在线免费 | 欧美一区视频 | 三极网站 | 97人人超碰| 国产黄视频在线播放 | 五月天综合网 | jav成人av免费播放 | 日本久久一区二区三区 | 国产乱码精品一区二区三区忘忧草 | 日韩午夜在线观看 | 欧美性生活免费 | 日韩在线免费视频 | 久久精品国产亚洲一区二区三区 | 亚洲精品免费视频 | 欧美亚洲在线 | 九七午夜剧场福利写真 | 亚洲成人一级片 | 午夜天堂精品久久久久 | 成人三级影院 | 久久av一区二区三区 | 男人天堂网址 | 97精品超碰一区二区三区 | 91欧美激情一区二区三区成人 | 91日b| 亚洲精品成人网 | 999热精品视频 | 在线a视频网站 | 欧美日韩免费 | 国产一区二区影院 | 神马久久久久久久久久 | 精品91| 成人亚洲 | 久久久久免费精品国产小说色大师 |