我一直在尝试新的Android构建系统,我遇到了一个小问题.我已经编译了自己的ActionBarSherlock的aar包,我称之为'actionbarsherlock.aar'.我正在尝试做的实际上是使用这个aar来构建我的最终APK.如果我使用编译项目(':actionbarsherlock')将整个ActionBarSherlock库作为android-library模块包含到我的主项目中,我可以成功构建而没有任何问题.
但我的问题是,我想将该依赖项作为aar文件包手动提供,如果我想要一个JAR,那么我似乎无法弄清楚如何正确地将它包含到我的项目中.我试图使用编译配置,但这似乎不起作用.我继续在编译期间找不到符号,这告诉我来自aar包的classes.jar没有包含在类路径中.
有谁知道手动将aar包作为文件包含的语法?
的build.gradle
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.4'
}
}
apply plugin: 'android'
repositories {
mavenCentral()
}
dependencies {
compile files('libs/actionbarsherlock.aar')
}
android {
compileSdkVersion 15
buildToolsVersion "17.0"
}
Run Code Online (Sandbox Code Playgroud)
编辑:所以答案是它目前不支持,如果你想跟踪它,这是问题.
编辑:目前仍然没有直接支持,最好的替代方案似乎是来自@RanWakshlak的建议解决方案
编辑:使用@VipulShah提出的语法也更简单
所以我创建了一个Android-Library,并成功地将其编译成.aar文件,我称之为aar文件:"projectx-sdk-1.0.0.aar"现在我希望我的新项目依赖于这个aar所以我所做的就是关注这篇文章:http:// life. nimbco.us/referencing-local-aar-files-with-android-studios-new-gradle-based-build-system/
但由于我没有得到预期的结果,这篇文章让我感到困惑:
aar的包名是:com.projectx.photosdk并调用里面的模块sdk
这是我目前的项目结构:
|-SuperAwesomeApp
|--.idea
|--gradle
|--App
|---aars
|----projectx-sdk-1.0.0.aar
|---build
|---jars
|---src
|---build.gradle
Run Code Online (Sandbox Code Playgroud)
他是我的gradle构建文件:
apply plugin: 'android'
buildscript {
repositories {
mavenCentral()
flatDir {
dirs 'aars'
}
}
}
android {
compileSdkVersion 19
buildToolsVersion "19.0.1"
defaultConfig {
minSdkVersion 11
targetSdkVersion 19
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile 'com.android.support:gridlayout-v7:19.0.1'
compile 'com.android.support:support-v4:19.0.1'
compile 'com.android.support:appcompat-v7:19.0.1'
compile 'com.projectx.photosdk:sdk:1.0.0@aar'
// compile files( …Run Code Online (Sandbox Code Playgroud) 我谷歌关于本地aar,每个人都说它可以工作,但它在android studio 1.1.0不起作用.
我尝试使用:
compile fileTree(dir: 'libs', include: ['*.aar'])
Run Code Online (Sandbox Code Playgroud)
但它提示:
Warning:Project app: Only Jar-type local dependencies are supported. Cannot handle: /Users/kycq/AndroidStudioProjects/QingTaJiao/app/libs/KycqBasic-release.aar
Run Code Online (Sandbox Code Playgroud)
我该怎么做才能使用当地的aar?如果我应该使用:
compile 'com.example.library:library:1.0.0@aar'
Run Code Online (Sandbox Code Playgroud)
这该怎么做?
我已经阅读了很多与此主题相关的答案,但是没有一个能够解决我的问题,所以需要帮助:
我需要将.aar文件导入到使用Android Studio 1.1.0创建的项目中,我使用"新模块"选项导入它,实际上我没有收到任何错误,我可以构建应用程序并运行它,但是当我尝试使用这个.aar文件中的类时,Android Studio没有找到对它的引用,让我们说它无法识别我想要包含在我的代码中的包.
您可能认为我必须添加依赖项,我已经这样做了,它似乎无法正常工作.
所以有人可以告诉我在Android Studio 1.1.0中导入和使用.aar文件的正确方法
我创建了一个安卓库,它包含一个用于打开相机意图的活动类,该库可以完美地用于调用活动显示在屏幕上的部分,并且应用程序崩溃时抛出以下错误
Suppressed: java.lang.ClassNotFoundException: com.me.scanner.ScannerViewActivity
at java.lang.Class.classForName(Native Method)
at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
... 14 more
Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack trace available
Run Code Online (Sandbox Code Playgroud)
以下是我build.gradle将使用此库的其他项目的文件
repositories {
flatDir {
dirs 'libs'
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.3.0'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'com.me.app:gpio_lib@aar'
compile ('com.me.app:scanner@aar'){ transitive = true; }
testCompile 'junit:junit:4.12'
}
Run Code Online (Sandbox Code Playgroud)
请注意:
这个库非常适合作为模块项目,
compile project(':scannercontrol')
Run Code Online (Sandbox Code Playgroud)
但不是aar在项目中使用它时
我有没有尝试 …
是否可以将Android Studio配置为仅显示项目文件夹@drawable内的资源?
我正在研究的项目是一个工业项目,很少需要我使用R资源.

出于各种原因,我处于这样一种情况,即我在小型孤立的android-library项目中存在多个应用程序组件,这些项目正在编译为.aars.
在某些情况下,这些被推送到maven回购并以这种方式消费,这很好,一切都很好.
在其他情况下,这些aars需要编译到另一个android库中.我当前的配置我有问题,因为孩子aar lib内容没有添加到父aar lib项目上gradlew assembleRelease.
依赖流程就像
Apk app project -> parentLibProject -*> childLibProject
这导致父级aar编译正常,因为子aars在类路径上但不包括输出父级aar中的子aar libs内容.这意味着任何使用父lib的android应用程序项目都会在编译时失败,因为子lib aar文件/代码不在父aar中.我不想强迫app项目手动列出已经在父lib项目中列出的所有子lib项目.从本质上讲,我希望aars以类似于jar库项目使用的库的方式处理,即编译到输出中aar.
我尝试了一些非成功的方法(所有构建都很好,但都无法将子aar lib内容输出到父aar lib文件中):
aar内部编译的子进程/libs/,在存储库闭包中声明flatDir { dirs 'libs' }并导入到父lib项目中compile(name:'someAarLib-x.y.z', ext:'aar').编译得很好但是父项目也需要包括someAarLib-x.y.zaar和compile(name:'someAarLib-x.y.z', ext:'aar').*.aar.这根本不起作用(在SO上的其他地方评论)我目前正在使用Gradle 2.3和android插件1.2.1.
现在我正在以一种hacky的方式将它拉出classes.jar孩子aar项目并放置父lib项目(根据/sf/answers/2328525671/),因为它恰好发生了他们不使用任何xml资源,所以在这种情况下我不会丢失任何东西.但这有点耗时,而且我不想做的手动工作也不是很有可扩展性.是的可以自动化这个,但我确定有一个正式的方式,我没有偶然发现正确的配置.
非常感谢任何帮助.
我有一个aar的socialauth功能的Android库添加到我的项目.我把它放在这里flatDir描述的目录中,它工作得很好.
现在,我将我的一些代码移动到名为的库模块中,以便在另一个项目中重用它.将完全由库模块使用,所以我把它移到了重写的文件中.从现在开始,我无法构建我的项目,因为出现以下错误: commonssocialauth-androidproject/commons/libs/build.gradle
Error:A problem occurred configuring project ':ScrollApplication'.
> Could not resolve all dependencies for configuration ':ScrollApplication:_developmentDebugCompile'.
> Could not find :socialauth-android:.
Searched in the following locations:
http://dl.bintray.com/populov/maven//socialauth-android//socialauth-android-.pom
http://dl.bintray.com/populov/maven//socialauth-android//socialauth-android-.aar
https://oss.sonatype.org/content/repositories/snapshots//socialauth-android//socialauth-android-.pom
https://oss.sonatype.org/content/repositories/snapshots//socialauth-android//socialauth-android-.aar
https://repo1.maven.org/maven2//socialauth-android//socialauth-android-3.2.pom
https://repo1.maven.org/maven2//socialauth-android//socialauth-android-3.2.aar
file:/home/artem/Workspace/scrollandroid/libraries/socialauth-android-3.2.aar
file:/home/artem/Workspace/scrollandroid/libraries/socialauth-android.aar
Required by:
scrollandroid:ScrollApplication:unspecified > scrollandroid:commons:unspecified
Run Code Online (Sandbox Code Playgroud)
错误说依赖解析器试图socialauth-android.aar在project/libraries文件夹中查找,该文件夹是我项目模块之间共享的所有公共库的文件夹.但我已经写在我的project/commons/build.gradle文件中flatDir的commons模块project/commons/libs!此外,jar包含在其中的所有库project/commons/libs/都可以在构建期间找到任何问题.
这个问题的根源是什么?
以下是我的build.gradle文件(为了简洁起见,删除了一些代码,例如依赖声明):
project/settings.gradle:
include ':ScrollApplication', ':commons'
Run Code Online (Sandbox Code Playgroud)
project/build.gradle:
buildscript {
repositories …Run Code Online (Sandbox Code Playgroud) 我正在为供应商制作一个库项目,它需要 Android Volley 作为依赖项。我已使用此在 Android Studio 中创建 aar 文件来创建 .aar 文件并将其包含在测试项目中,我正在使用此使用“flatDirs”将本地 .aar 文件添加到 Gradle 构建不起作用。该库链接良好,项目编译没有错误。但在运行时测试应用程序崩溃并表示找不到 Volley
java.lang.NoClassDefFoundError: Failed resolution of: Lcom/android/volley/toolbox/Volley;
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.android.volley.toolbox.Volley" on path: DexPathList[[zip file "/data/app/in.gridsync.acttest-1/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available
Run Code Online (Sandbox Code Playgroud)
我的库项目的 Gradle 文件是这样的
apply plugin: 'com.android.library'
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
defaultConfig {
minSdkVersion 14
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled …Run Code Online (Sandbox Code Playgroud) 我创建了一个名为“core”的 Android 库,它使用 Logger 库 ( https://github.com/orhanobut/logger )。
这里是build.gradle:
apply plugin: 'com.android.library'
android {
compileSdkVersion 25
buildToolsVersion "25.0.1"
defaultConfig {
minSdkVersion 16
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.orhanobut:logger:1.15'
compile 'com.android.support:appcompat-v7:25.0.1'
testCompile 'junit:junit:4.12'
}
Run Code Online (Sandbox Code Playgroud)
然后我构建了一个.aar核心库。
我通过将.aar核心文件放在libs文件夹中,将此库作为依赖项添加到我的应用程序中。
这就是build.gradle我的应用程序:
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.0.1"
defaultConfig …Run Code Online (Sandbox Code Playgroud)