Gradle 多环境URL请求设置
来源:互联网 发布:蜘蛛源码 编辑:程序博客网 时间:2024/06/05 12:46
在开发过程中,多环境配置是经常遇到的,比如在Android开发过程中,在不同环境上请求服务器的URL是不同的,使用Gradle进行管理,是非常方便的。
首先查看工程目录结构:
使用AndroidStudio开发的看到这个熟悉吧。main就是目前开发的环境。dev为测试环境。product,staging为其他环境,当然还可以有其他更多环境。
1、将请求的URL定义到Constant常量类中:
public class Constant {
public static final String URL= “http://XXXXX“;
}
在dev,product,staging等环境中添加Constant类,并且设置不同URL即可。
设置后目录结构如下:我的app包名为com.example.XX.myapplication
这里需要注意的是不要在main环境中添加Constant类,否则类就重复了,Gradle编译时会报:dumplicate class XXX
使用时就和普通类使用方式一样!
Gradle配置:
apply plugin: 'com.android.application'android { compileSdkVersion 21 buildToolsVersion "19.1.0" lintOptions { abortOnError false } defaultConfig { applicationId "com.example.teamlab.myapplication" minSdkVersion 9 targetSdkVersion 21 versionCode 1 versionName "1.0" } signingConfigs { debug { storeFile file("src/main/keystore/debug.keystore") storePassword "android" keyPassword "android" } release { storeFile file("src/main/keystore/debug.keystore") storePassword "android" keyPassword "android" } staging { storeFile file("src/main/keystore/debug.keystore") storePassword "android" keyPassword "android" } } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } debug { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } productFlavors { dev { applicationId 'com.example.teamlab.myapplication.dev' signingConfig signingConfigs.debug } staging { signingConfig signingConfigs.debug applicationId 'com.example.teamlab.myapplication.staging' } product { applicationId 'com.example.teamlab.myapplication' signingConfig signingConfigs.debug } } packagingOptions { exclude 'META-INF/notice.txt' exclude 'META-INF/license.txt' }}dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) compile 'com.android.support:appcompat-v7:21.+' compile 'com.android.support:support-v4:21.+' compile 'cn.pedant.sweetalert:library:1.3' compile 'com.mcxiaoke.volley:library:1.0.+' androidTestCompile 'junit:junit:4.10' androidTestCompile 'org.robolectric:robolectric:2.3+' androidTestCompile 'com.squareup:fest-android:1.0.+' compile project(':slidingmenu')}
0 0
- Gradle 多环境URL请求设置
- postman设置环境变量,实现一套接口根据选择的环境去请求不同的url
- Gradle 多环境配置
- Gradle 多环境配置
- Gradle多环境配置
- Gradle buildTypes 设置自动打包环境
- 发送设置编码的Url请求
- Gradle 的repositories 配置多个URL
- Gradle 多环境、多渠道打包
- Gradle多环境多渠道打包
- 请求URL
- url请求
- Android Studio设置自动打包环境-Gradle buildTypes配置
- 设置java.net.URL请求方式post get
- Python设置http的header请求访问URL
- Gradle多渠道多环境打包自动重命名
- Android 使用gradle配置多环境打包
- nutch 在hadoop环境下过滤抓取url的设置
- Android 使用Fragment,ViewPagerIndicator主要框架(制作csdn app一)
- CSS实现iphone式开关
- android开发中像素单位介绍
- 警告框小知识
- 中国城市util类
- Gradle 多环境URL请求设置
- Concrete formly brown film faced plywood big size
- 黑马程序员--JAVA基础---多线程
- redis多端口新建实例
- cocos2dx 教程收藏
- auto_ptr,scoped_ptr,shared_ptr,weak_ptr区别
- FlappyBird开发总结(七)—— GameOver计分板
- 正则表达式(多行匹配,不以某某开头,不区分大小写,2个单元的或操作)
- 文通旅行社护照录入产品国际旅游展上受追捧