Friday, October 16, 2015
android studio build.gradle quick couse 1 by pkrss
== android studio build.gradle ==
1.define custom variable in module build.gradle:
///////////////////////////////////////////////////////////////////////////////
//
def a = true
def b = "string"
//
///////////////////////////////////////////////////////////////////////////////
2.use if condition variable in module build.gradle:
///////////////////////////////////////////////////////////////////////////////
//
if(a)
apply plugin: 'com.android.library'
else
apply plugin: 'com.android.application'
//
///////////////////////////////////////////////////////////////////////////////
3.define custom global whole module variable in one project build.gradle:
///////////////////////////////////////////////////////////////////////////////
//
1. define it in project root build.gradle:
project.ext.set("buildRelease", true)
2.used it in sub module build.gradle:
if(buildRelease)
apply plugin: 'com.android.library'
else
apply plugin: 'com.android.application'
//
///////////////////////////////////////////////////////////////////////////////
4.define task in build.gradle: (sample with widows path style)
///////////////////////////////////////////////////////////////////////////////
//
def proguardJar(String target){
exec{
workingDir './../../tools/guard'
commandLine 'cmd', '/c', 'proguard5.2.1\\bin\\proguard.bat',"-include", 'profile/' + target + '.txt'
}
}
def makeJar(String target){
exec{
executable "jar" //jar program
args "cvf","../../tools/guard/injars/" + target + ".jar"
args "-C", "../" + target + "/build/intermediates/classes/release"
args "","."
}
proguardJar(target)
}
def releaseDocSource(String ver){
exec{
workingDir './../../tools/bat'
commandLine 'cmd', '/c', 'copyres.bat',ver
}
}
task buildLib(dependsOn:['build'])<< {
makeJar("benshoujisdk")
releaseDocSource("1.1.13")
}
//
///////////////////////////////////////////////////////////////////////////////
5. how to run custom task in android studio
///////////////////////////////////////////////////////////////////////////////
//
it is called 'Gradle projects', in right panel of android studio, then click num 4 button, it likes green ring, and comment 'Execute Gradle Task'. then will open one popup window
line one Gradle project: click right drop button,select one project,
line two Command line: type task name, like above "buildLib"
line three: click ok.
after that,you can see the logs in "Run" or "Gradle Console" panel in the bottom of android studio.
//
///////////////////////////////////////////////////////////////////////////////
6. how to add one exist android studio module in android studio project.
///////////////////////////////////////////////////////////////////////////////
//
copy your exist andriod studio module folder into andriod studio project.
then edit settings.gradle, and add it: include ':your new module folder name'
//
///////////////////////////////////////////////////////////////////////////////
7. what is the shortkey like undo ctrl+z
///////////////////////////////////////////////////////////////////////////////
//
in some editor,it call ctrl+y,but in android studio,default is shirt+ctrl+z
and:
alt+f7: see useage of some class or function
f7: step in
f8: step over
f9: run
esc: close quick search float bar
//
///////////////////////////////////////////////////////////////////////////////
8. add some libs or module or aar depends
///////////////////////////////////////////////////////////////////////////////
//
1.edit your module/build.gradle:
dependencies {
compile(name: 'CyberLink4Android', ext: 'aar') // add depends: CyberLink4Android aar
// compile fileTree(include: ['*.jar'], dir: 'libs') // add depends: all libs/* jar
compile 'com.android.support:support-v4:23.0.1' // add depends: android.support.v4 by online mode
compile project(':mdns') // add depends: mdns module project depends
}
//
///////////////////////////////////////////////////////////////////////////////
9. jni ndk developer quickly tip
///////////////////////////////////////////////////////////////////////////////
//
1.install ndk
edit your ndk and sdk path in local.properties,like this:
ndk.dir=D\:\\sdk\\android-ndk-r10e
sdk.dir=D\:\\sdk\\androidsdk
2.copy files into your module/src/main/jni
3.edit gradle.properties,if not exist,create it
android.useDeprecatedNdk=true
4,edit your module build.gradle, like bellow: (some is not need,modify as your need)
android {
sourceSets.main {
jniLibs.srcDir 'src/main/libs'
jni.srcDirs = []
}
defaultConfig {
ndk {
moduleName "jdns_sd"
ldLibs "log"
abiFilters "armeabi", "x86"
cFlags "-DMDNS_DEBUGMSGS=0 -DTARGET_OS_ANDROID -DUSES_BROADCAST_AND_MULTICAST -DNOT_HAVE_SA_LEN -DUSES_NETLINK" +
" -I${project.buildDir}/../src/main/jni -I${project.buildDir}/../src/main/jni/mDNSShared -I${project.buildDir}/../src/main/jni/mDNSCore -I${project.buildDir}/../src/main/jni/mDNSPosix"
}
}
buildTypes {
release {
debuggable false
jniDebuggable false
minifyEnabled false
}
debug {
debuggable true
jniDebuggable true
ndk {
cFlags "-g -D_DEBUG -UNDEBUG"
}
}
}
}
task genJavaH(dependsOn: ['build']) << {
exec {
workingDir 'src/main'
commandLine 'javah', '-force', '../../build/intermediates/classes/debug', '-o', 'jni/DNSSD.java.h','com.apple.dnssd.AppleDNSSD com.apple.dnssd.AppleBrowser com.apple.dnssd.AppleResolver com.apple.dnssd.AppleRegistration com.apple.dnssd.AppleQuery com.apple.dnssd.AppleDomainEnum com.apple.dnssd.AppleService com.apple.dnssd.AppleDNSRecord com.apple.dnssd.DNSSDEmbedded'
}
}
//
///////////////////////////////////////////////////////////////////////////////
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment