在Google
IO中,宣布了新的构建系统gradle来替换ant。我的项目正在使用Aspectj,我想在我的项目中使用它。我无法弄清楚一些变量使其正常工作。我在那里找不到android。*输出类路径。有人可以帮忙吗?
这是我当前的build.gradle:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.4'
}
}
apply plugin: 'android'
sourceCompatibility = 1.6
configurations {
ajc
}
dependencies {
compile fileTree(dir: 'libs', includes: ['*.jar'])
ajc files('build-tools/aspectjtools.jar', 'libs/aspectjrt.jar')
}
android {
compileSdkVersion 16
buildToolsVersion "17"
defaultConfig {
minSdkVersion 8
targetSdkVersion 16
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
instrumentTest.setRoot('test')
}
}
gradle.projectsEvaluated {
compileJava.doLast {
tasks.compileAspectJ.execute()
}
println 'lalalalala'
}
task compileAspectJ {
ant.taskdef(resource: "org/aspectj/tools/ant/taskdefs/aspectjTaskdefs.properties",
classpath: configurations.ajc.asPath)
ant.iajc(source: sourceCompatibility, target: sourceCompatibility,
destDir: "?????????????????????",
classpath: "????????????????????????????") {
sourceroots{
android.sourceSets.main.java.srcDirs.each {
pathelement(location: it.absolutePath)
}
}
}
}
这是旧的ant代码,效果很好:http:
//code.google.com/p/anymemo/source/browse/custom_rules.xml
编辑:
根据第一个答案更新了build.gradle,但是我的Iajc似乎无法识别所有库并且抱怨找不到库中的类
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.5.+'
}
}
apply plugin: 'android'
sourceCompatibility = 1.6
targetCompatibility = 1.6
repositories {
mavenCentral()
}
android {
compileSdkVersion 18
buildToolsVersion "18.1.0"
defaultConfig {
minSdkVersion 9
targetSdkVersion 16
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
// Move the tests to tests/java, tests/res, etc...
instrumentTest.setRoot('tests')
// Move the build types to build-types/<type>
// For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
// This moves them out of them default location under src/<type>/... which would
// conflict with src/ being used by the main source set.
// Adding new build types or product flavors should be accompanied
// by a similar customization.
debug.setRoot('build-types/debug')
release.setRoot('build-types/release')
}
}
configurations {
ajc
aspects
ajInpath
}
ext.aspectjVersion = '1.7.3'
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
ajc "org.aspectj:aspectjtools:${aspectjVersion}"
compile "org.aspectj:aspectjrt:${aspectjVersion}"
compile 'com.android.support:appcompat-v7:18.0.0'
}
android.applicationVariants.all { variant ->
variant.javaCompile.doLast {
def androidSdk = android.adbExe.parent + "/../platforms/" + android.compileSdkVersion + "/android.jar"
println 'AAAAAAAAAAAAAAAAA: ' + androidSdk
def iajcClasspath = configurations.compile.asPath + ":" + androidSdk
configurations.compile.dependencies.each { dep ->
if(dep.hasProperty("dependencyProject")) {
iajcClasspath += ":" + dep.dependencyProject.buildDir + "/bundles/release/classes.jar"
}
}
println 'BBBBBBBBBBBBBB : ' + iajcClasspath
ant.taskdef( resource:"org/aspectj/tools/ant/taskdefs/aspectjTaskdefs.properties", classpath: configurations.ajc.asPath)
ant.iajc (
source:sourceCompatibility,
target:targetCompatibility,
destDir:"${project.buildDir}/classes/${variant.dirName}",
maxmem:"512m",
fork:"true",
aspectPath:configurations.aspects.asPath,
inpath:configurations.ajInpath.asPath,
sourceRootCopyFilter:"**/.svn/*,**/*.java",
classpath:iajcClasspath
){
sourceroots{
android.sourceSets.main.java.srcDirs.each{
pathelement(location:it.absolutePath)
}
pathelement(location:"${project.buildDir}/source/r/${variant.dirName}")
}
}
}
}
错误:
1 [error] The method onPrepareOptionsMenu(Menu) of type FingerPaint must override or impl[3780/18642]
rtype method
[ant:iajc] public boolean onPrepareOptionsMenu(Menu menu) {
[ant:iajc] ^^^^^^^^^^^^^^^^^^^^^^^^^^
[ant:iajc] /home/liberty/mp/android/AnyMemo/src/com/example/android/apis/graphics/FingerPaint.java:21
2 [error] The method onPrepareOptionsMenu(Menu) is undefined for the type GraphicsActivity
[ant:iajc] super.onPrepareOptionsMenu(menu);
[ant:iajc] ^^^^^^^^^^^
[ant:iajc] /home/liberty/mp/android/AnyMemo/src/com/example/android/apis/graphics/FingerPaint.java:21
7 [error] The method onOptionsItemSelected(MenuItem) of type FingerPaint must override or implement a
supertype method
[ant:iajc] public boolean onOptionsItemSelected(MenuItem item) {
[ant:iajc] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[ant:iajc] /home/liberty/mp/android/AnyMemo/src/com/example/android/apis/graphics/FingerPaint.java:22
8 [error] The constructor ColorPickerDialog(FingerPaint, FingerPaint, int) is undefined
[ant:iajc] new ColorPickerDialog(this, this, mPaint.getColor()).show();
[ant:iajc] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[ant:iajc] /home/liberty/mp/android/AnyMemo/src/com/example/android/apis/graphics/FingerPaint.java:25
4 [error] The method onOptionsItemSelected(MenuItem) is undefined for the type GraphicsActivity
[ant:iajc] return super.onOptionsItemSelected(item);
[ant:iajc] ^^^^^^^^^^^^
[ant:iajc] /home/liberty/mp/android/AnyMemo/src/com/example/android/apis/graphics/FingerPaint.java:25
8 [error] The method getDefaultSharedPreferences(Context) in the type PreferenceManager is not applic
able for the arguments (FingerPaint)
[ant:iajc] SharedPreferences shre = PreferenceManager.getDefaultSharedPreferences(this);
[ant:iajc]
编辑:这是适用于我的项目的最终build.gradle文件:https
:
//code.google.com/p/anymemo/source/browse/build.gradle?
spec=svnf85aaa4b2d78c62876d0e1f6c3e28252bf03f820&r=f85aaa4b2d78c62876d0e1f6f
我发现AAR不能在我的代码中用作jar库。如果您正在使用这样的依赖项
compile 'com.android.support:appcompat-v7:18.0.0'
您需要找到jar文件并将其添加到类路径中。下面的代码可以做到这一点。
tree = fileTree(dir: "${project.buildDir}/exploded-bundles", include: '**/classes.jar')
tree.each { jarFile ->
iajcClasspath += ":" + jarFile
}
因此,整个部分将是:
variant.javaCompile.doLast {
// Find the android.jar and add to iajc classpath
def androidSdk = android.adbExe.parent + "/../platforms/" + android.compileSdkVersion + "/android.jar"
println 'Android SDK android.jar path: ' + androidSdk
def iajcClasspath = androidSdk + ":" + configurations.compile.asPath
configurations.compile.dependencies.each { dep ->
if(dep.hasProperty("dependencyProject")) {
iajcClasspath += ":" + dep.dependencyProject.buildDir + "/bundles/release/classes.jar"
}
}
// handle aar dependencies pulled in by gradle (Android support library and etc)
tree = fileTree(dir: "${project.buildDir}/exploded-bundles", include: '**/classes.jar')
tree.each { jarFile ->
iajcClasspath += ":" + jarFile
}
println 'Classpath for iajc: ' + iajcClasspath
ant.taskdef( resource:"org/aspectj/tools/ant/taskdefs/aspectjTaskdefs.properties", classpath: configurations.ajc.asPath)
有关完整的示例,请在此处查看AnyMemo项目的build.gradle:https://code.google.com/p/anymemo/source/browse/build.gradle?
spec = svnf85aaa4b2d78c62876d0e1f6c3e28252bf03f820&r =
f85aaa4b2d78c62876d0e1f6
问题内容: 我将很快开始一个新的C++项目(它可能也包含一些C组件),并且我正在寻找一个现代的,具有工业实力的(即非beta)构建系统。该软件将由3-5个开发人员在3-5年内创建,并将在Linux上运行(稍后 可能 会支持Mac OS X和Windows )。我正在寻找一种比例如具有更好的可理解性,易用性和可维护性,但仍足以处理复杂项目的功能。首选开源软件。 我开始寻找到,,和到目前为止,喜欢的功
13. 构建系统 强烈建议您选择一个支持依赖管理的构建系统,而且这个构建系统能够使用发布到“Maven Central”库中的组件。我们建议您选择Maven或Gradle。Spring Boot有可能与其他构建系统(例如Ant)一起工作,但是其他构建系统不会得到特别好的支持。
强烈建议您选择支持依赖关系管理且可以使用发布到“Maven Central”存储库的artifacts的构建系统。 我们建议您选择Maven或Gradle。 可以让Spring Boot与其他构建系统(例如Ant)一起工作,但它们并没有得到特别好的支持。
所以我今天在Android studio中创建了一个新项目“2021.1.1金丝雀3”版本,但它无法正确构建我的项目。 这是Gradle的App版本: 下面是我的Gradle的项目版本: 以下是settings.gradle: 我也尝试过将静态编程语言的版本降低到1.5.0也不起作用,因为我已经搜索了很长一段时间,没有找到任何像我这样的东西,希望它可以向谷歌报告这个版本中的严重问题。
问题是如何启用堆栈跟踪,以便找到错误的根源。事实上,我真的不知道是什么引起的。
采用Gradle作为新构建系统的目标: 让重用代码和资源变得更加容易。 让创建同一应用程序的不同版本变得更加容易,无论是多个apk发布版本还是同一个应用的不同定制版本。 让构建过程变得更加容易配置,扩展和定制。 整合优秀的IDE