Last active
May 1, 2016 14:00
-
-
Save xxnjdlys/11b83f4baf55448ccf41 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* configures the code driving the build. | |
* In this case, this declares that it uses the Maven Central repository, | |
* and that there is a classpath dependency on a Maven artifact. | |
* Note: This only affects the code running the build, not the project. | |
* The project itself needs to declare its own repositories and dependencies. This will be covered later. | |
*/ | |
buildscript { | |
repositories { | |
mavenCentral() | |
} | |
dependencies { | |
classpath 'com.android.tools.build:gradle:0.12.2' | |
} | |
} | |
apply plugin: 'com.android.application' | |
/** | |
* Gradle supports pulling artifacts from Maven and Ivy repositories. | |
* First the repository must be added to the list, | |
* and then the dependency must be declared in a way that Maven or Ivy declare their artifacts. | |
* Note: mavenCentral() is a shortcut to specifying the URL of the repository. Gradle supports both remote and local repositories. | |
* Note: Gradle will follow all dependencies transitively. This means that if a dependency has dependencies of its own, those are pulled in as well. | |
* For more information about setting up dependencies, read the Gradle user guide {1}, and DSL documentation {2}. | |
* | |
* {1}: http://www.gradle.org/docs/current/userguide/artifact_dependencies_tutorial.html | |
* {2}: http://www.gradle.org/docs/current/dsl/org.gradle.api.artifacts.dsl.DependencyHandler.html | |
*/ | |
repositories { | |
mavenCentral() | |
} | |
/** | |
* configures all the parameters for the android build. This is the entry point for the Android DSL. | |
* By default, only the compilation target, and the version of the build-tools are needed. | |
* This is done with the compileSdkVersion and buildtoolsVersion properties. | |
* The compilation target is the same as the target property in the project.properties file of the old build system. | |
* This new property can either be assigned a int (the api level) or a string with the same value as the previous target property. | |
*/ | |
android { | |
compileSdkVersion 20 | |
buildToolsVersion '20.0.0' | |
/** | |
* The defaultConfig element inside the android element is where all this configuration is defined. | |
* | |
* Previous versions of the Android Plugin used packageName to configure the manifest 'packageName' attribute. | |
* Starting in 0.11.0, you should use applicationId in the build.gradle to configure the manifest 'packageName' entry. | |
* This was disambiguated to reduce confusion between the application's packageName (which is its ID) and | |
* java packages. | |
*/ | |
defaultConfig { | |
applicationId 'com.wukongtv.wkremote.client' | |
minSdkVersion 9 | |
targetSdkVersion 20 | |
versionCode 50 | |
versionName "0.5.0" | |
} | |
final Console console = System.console(); | |
if (console != null) { | |
signingConfigs { | |
/** | |
* see http://stackoverflow.com/questions/18328730/how-to-create-a-release-signed-apk-file-using-gradle for help | |
*/ | |
release { | |
storeFile file(System.getenv("KEYSTORE_WKTV")) | |
storePassword System.getenv("KEYSTORE_PWD_WKTV") | |
keyAlias System.getenv("KEY_ALIAS_WKTV") | |
keyPassword System.getenv("KEYSTORE_PWD_WKTV") | |
} | |
} | |
} else { | |
signingConfigs { | |
release {} | |
} | |
} | |
def File customerProguardFile = file('src/proguard.cfg') | |
/** | |
* By default, the Android plugin automatically sets up the project to build both a debug and a release version of the application. | |
* These differ mostly around the ability to debug the application on a secure (non dev) devices, and how the APK is signed. | |
*/ | |
buildTypes { | |
release { | |
/** | |
* run proguard file in release version | |
*/ | |
runProguard true | |
/** | |
* using customer proguard file instead | |
* copy proguard file from /sdk/tools/proguard/proguard-android.txt(proguard-android-optimize.txt) | |
* rename as proguard.cfg and put it in src folder | |
*/ | |
proguardFile customerProguardFile | |
signingConfig signingConfigs.release | |
} | |
} | |
/** | |
* A product flavor defines a customized version of the application build by the project. | |
* A single project can have different flavors which change the generated application. | |
* This new concept is designed to help when the differences are very minimum. | |
* If the answer to “Is this the same application?” is yes, then this is probably the way to go over Library Projects. | |
*/ | |
productFlavors { | |
UMENG_CHANNEL_VALUE{proguardFile 'proguard-rules.txt'} | |
aitv {proguardFile 'proguard-rules.txt'} | |
wostore {proguardFile 'proguard-rules.txt'} | |
taobao {proguardFile 'proguard-rules.txt'} | |
fenxiang {proguardFile 'proguard-rules.txt'} | |
erweima {proguardFile 'proguard-rules.txt'} | |
mumayi {proguardFile 'proguard-rules.txt'} | |
googleplay {proguardFile 'proguard-rules.txt'} | |
wandoujia {proguardFile 'proguard-rules.txt'} | |
xiaomi {proguardFile 'proguard-rules.txt'} | |
baidu {proguardFile 'proguard-rules.txt'} | |
qihu {proguardFile 'proguard-rules.txt'} | |
meizu {proguardFile 'proguard-rules.txt'} | |
yingyongbao {proguardFile 'proguard-rules.txt'} | |
anzhuo {proguardFile 'proguard-rules.txt'} | |
anzhi {proguardFile 'proguard-rules.txt'} | |
jifeng {proguardFile 'proguard-rules.txt'} | |
huawei {proguardFile 'proguard-rules.txt'} | |
nduo {proguardFile 'proguard-rules.txt'} | |
update {proguardFile 'proguard-rules.txt'} | |
} | |
} | |
/**Build Type + Product Flavor = Build Variant*/ | |
/** | |
* Building and Tasks | |
* | |
* When Product Flavors are used, more assemble-type tasks are created. These are: | |
1.assemble<Variant Name> | |
2.assemble<Build Type Name> | |
3.assemble<Product Flavor Name> | |
#1 allows directly building a single variant. For instance assembleFlavor1Debug. | |
#2 allows building all APKs for a given Build Type. For instance assembleDebug will build both Flavor1Debug and Flavor2Debug variants. | |
#3 allows building all APKs for a given flavor. For instance assembleFlavor1 will build both Flavor1Debug and Flavor1Release variants. | |
The task assemble will build all possible variants. | |
*/ | |
/** | |
* In Android projects, this is a bit more complicated because there could be a large number of the same task and | |
* their name is generated based on the Build Types and Product Flavors. | |
* see http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Manipulating-tasks for help | |
*/ | |
android.applicationVariants.all { variant -> | |
variant.processManifest.doLast { | |
copy { | |
from("${buildDir}/manifests") { | |
include "${variant.dirName}/AndroidManifest.xml" | |
} | |
into("${buildDir}/manifests/$variant.name") | |
filter { | |
String linechannel -> linechannel.replaceAll("UMENG_CHANNEL_VALUE", "${variant.productFlavors[0].name}") | |
} | |
variant.processResources.manifestFile = file("${buildDir}/manifests/${variant.name}/${variant.dirName}/AndroidManifest.xml") | |
} | |
} | |
} | |
/** | |
* see http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Dependencies-Android-Libraries-and-Multi-project-setup for help | |
*/ | |
dependencies { | |
/** | |
* solve problem in: | |
* http://stackoverflow.com/questions/24436678/manifest-merger-failed-uses-sdkminsdkversion-10-cannot-be-smaller-than-versio | |
*/ | |
compile('com.android.support:support-v4:20.0.0') { | |
force = true | |
} | |
/** | |
* solve problem in: | |
* http://stackoverflow.com/questions/24436678/manifest-merger-failed-uses-sdkminsdkversion-10-cannot-be-smaller-than-versio | |
*/ | |
compile('com.android.support:appcompat-v7:20.0.0') { | |
force = true | |
} | |
compile 'com.github.chrisbanes.actionbarpulltorefresh:extra-abc:0.9.2' | |
compile 'com.nostra13.universalimageloader:universal-image-loader:1.9.1' | |
/** avoid using + in version numblers , + may lead to the latest version of a library */ | |
//compile 'com.google.code.gson:gson:2.2.+' | |
compile 'com.google.code.gson:gson:2.2.4' | |
compile 'com.makeramen:roundedimageview:1.3.0' | |
/* import library from mavencenter*/ | |
compile 'com.squareup:otto:1.3.5' | |
/* import project as library */ | |
compile project(':common') | |
/* To configure a dependency on an external library jar (import local packages)*/ | |
compile fileTree(dir: 'libs', include: ['*.jar', '*.aar']) | |
} | |
/** | |
* complile project with UTF-8 | |
*/ | |
tasks.withType(JavaCompile) { | |
options.encoding = "UTF-8" | |
} | |
/** | |
* test task of reading proguard file from project | |
* in fact file proguard.cfg is just a copy of /sdk/tools/proguard/proguard-android.txt | |
*/ | |
task loadfile << { | |
customerProguardFile = file('src/proguard.cfg') | |
println "Proguard File path: " + customerProguardFile.path | |
println "Proguard File name: " + customerProguardFile.name | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Good luck and enjoy it .