我一直在使用本教程来教育自己如何使用命令行(和Ant) – http://www.androidengineer.com/2010/06/using-ant-to-automate-building-android.html在Eclipse外部构建APK
现在构建系统将转向Gradle我希望有类似的高级教程供参考.那里的大多数教程(like this one)只涉及基本的东西,但我想知道如何执行一些“高级”的东西,比如在构建期间自动替换代码中的值(这样我就可以有多种APK版本).最佳答案Google提供的标准示例如下
http://tools.android.com/tech-docs/new-build-system/gradle-samples-0.4.2.zip?attredirects=0&d=1
要在代码中自动更改值,请使用BuildConfig类.示例在上面的链接中.
变量在这里解释http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Build-Variants
UPDATE
因为这个例子在这里有点陈旧是pasetbin到更新的版本http://pastebin.com/FmcCZwA5
主要区别是插件提供的Robolectric支持,以及从SDK内部仓库获取的支持库
旧版本
Robolectric和AndroIDAnnotations的基本示例
使用nexus
buildscript { repositorIEs { mavenCentral() } dependencIEs { classpath 'com.androID.tools.build:gradle:0.4' }}apply plugin: 'androID'repositorIEs { mavenCentral() maven { url 'https://oss.sonatype.org/content/repositorIEs/snapshots/' }}
使用AndroIDAnnotation处理器,Robolectric本地测试和杰克逊
configurations { compile testLocalCompile.extendsFrom(compile) androIDannotations.extendsFrom(compile)}dependencIEs { compile files('libs/androID-support-v4.jar') compile 'org.androIDannotations:androIDannotations-API:3.0-SNAPSHOT' compile 'com.github.japgolly.androID:svg-androID:2.0.3' compile 'org.codehaus.jackson:jackson-mapper-asl:1.9.12' testLocalCompile 'junit:junit:4.8.2' testLocalCompile 'org.robolectric:robolectric:2.2-SNAPSHOT' testLocalCompile 'com.Google.androID:androID:4.0.1.2' testLocalCompile 'com.Google.androID:support-v4:r6' testLocalCompile 'org.roboguice:roboguice:2.0' androIDannotations 'org.androIDannotations:androIDannotations:3.0-SNAPSHOT'}androID { compileSdkVersion 17 buildToolsversion "17.0.0"
配置标准检测测试
defaultConfig { minSdkVersion 7 targetSdkVersion 16 testPackagename "com.mypackage.myapp.test" testInstrumentationRunner "com.maypackage.myapp.test.Runner" }}
在所有变体上调用AndroIDAnnotations处理器
afterEvaluate { project -> androID.applicationVariants.each { variant -> variant.javaCompile.options.compilerArgs += [ '-classpath',configurations.compile.asPath,'-processorpath',configurations.androIDannotations.asPath,'-processor','org.androIDannotations.AndroIDAnnotationProcessor','-AandroIDManifestfile=' + variant.processResources.manifestfile ] }}
定义Robolectric本地测试的源集
sourceSets { testLocal { java.srcDir file('src/test/java') resources.srcDir file('src/test/resources') }}
本地Robolectric测试任务
task localTest(type: Test,dependsOn: assemble) { testClassesDir = sourceSets.testLocal.output.classesDir androID.sourceSets.main.java.srcDirs.each { dir -> def buildDir = dir.getabsolutePath().split('/') buildDir = (buildDir[0..(buildDir.length - 4)] + ['build','classes','deBUG']).join('/') sourceSets.testLocal.compileClasspath += files(buildDir) sourceSets.testLocal.runtimeClasspath += files(buildDir)}classpath = sourceSets.testLocal.runtimeClasspath
}
在调试模式下运行Robolectric
localTest.doFirst { jvmArgs '-XdeBUG','-XrunjDWp:transport=dt_socket,server=y,suspend=y,address=5005'}
总结 以上是内存溢出为你收集整理的android – 在IDE外部使用Gradle构建APK(从Ant迁移)全部内容,希望文章能够帮你解决android – 在IDE外部使用Gradle构建APK(从Ant迁移)所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)