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

BuildConfig 未正確創建(Gradle Android)

BuildConfig not getting created correctly (Gradle Android)(BuildConfig 未正確創建(Gradle Android))
本文介紹了BuildConfig 未正確創建(Gradle Android)的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我正在嘗試將我們的 Android 應用程序轉換為 gradle 版本.我有這個項目,它的圖書館建設成功.我現在正在嘗試為我們的各種環境創建單獨的 apk(dev/test/prod 對它們使用的 restful 服務有不同的 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).

在四處搜索時,我認為最好的方法是為每個環境制作不同的 BuildConfig.這是我嘗試過的:

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']
        }
    }
}

問題是我的 BuildConfig.java 似乎沒有注入靜態變量,因此我收到類似以下的錯誤:

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

我做錯了什么?

推薦答案

請確保您正在構建dev"或prod"變體.默認的調試"和發布"變體中沒有 BuildConfig 定義.在 Android Studio 中,您可以在左下角選擇當前變體:

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

然后只使用默認的調試"和發布"變體.

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

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

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

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

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

相關文檔推薦

IncompatibleClassChangeError after updating to Android Build Tools 25.1.6 GCM / FCM(更新到 Android Build Tools 25.1.6 GCM/FCM 后出現 IncompatibleClassChangeError)
How to get current flavor in gradle(如何在 gradle 中獲取當前風味)
How to fix quot;unexpected element lt;queriesgt; found in lt;manifestgt;quot; error?(如何修復“意外元素lt;查詢gt;在“清單中找到錯誤?)
Multi flavor app based on multi flavor library in Android Gradle(基于 Android Gradle 中多風味庫的多風味應用)
Android dependency has different version for the compile and runtime(Android 依賴在編譯和運行時有不同的版本)
Transitive dependencies for local aar library(本地 aar 庫的傳遞依賴)
主站蜘蛛池模板: 日韩欧美一级精品久久 | 中文字幕在线观看一区二区 | 一级黄色片美国 | 国内精品久久久久久 | 欧美黑人一级爽快片淫片高清 | 国产精品久久久久无码av | 亚洲日本中文 | 影视先锋av资源噜噜 | 久久99精品久久久久久国产越南 | 色欧美片视频在线观看 | 中文字幕一区二区三区乱码图片 | 色视频一区二区 | 色av一区二区三区 | 国产激情视频网站 | 国产精品久久精品 | 国产区精品 | 中文字幕一二三 | 日韩在线中文 | 亚洲国产精选 | 精品日本久久久久久久久久 | 亚洲成人av | 青青草一区 | 欧美8一10sex性hd | 狠狠艹| 欧美精品一区在线 | 99久久婷婷国产综合精品电影 | 欧美一级欧美一级在线播放 | 成人免费av | 在线看一区二区 | 日韩三区 | 久久久网| 亚洲一区二区久久 | 欧美日韩黄 | 日韩影音 | 国产成人免费视频网站高清观看视频 | 一级毛片免费视频 | 亚洲一区在线免费观看 | 久久精品成人 | 午夜影院网站 | 亚洲精品乱码久久久久久久久久 | 99pao成人国产永久免费视频 |