你能帮我理解构建android库的一般概念,并在用户的应用程序中使用它.
所以,有以下情况:
在android studio中有以下模块:
核心
数据
绘图
并且有一个模块
应用程序
依赖于上述模块.
app.gradle
dependencies {
compile project(':core')
compile project(':data')
compile project(':drawing')
}
Run Code Online (Sandbox Code Playgroud)
所以我可以从Android Studio运行该应用程序.
但我希望有类似AAR文件的东西,并将其包含在任何应用程序中,以便能够再次使用它而无需创建相同的模块.
我对Gradle不是很熟悉,所以我不确定是否可能以及如何做到这一点.
我正在实现一个具有推送通知和api的库项目.在这个库中,我使用了一些外部库,如playservice-gcm,gson,retrofit等.如果我用库项目编译示例,那么一切都很好.但是当我使用aar文件时,示例项目无法找到我使用的外部库.
下面是我的库的builde.gradle:
apply plugin: 'com.android.library'
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
minSdkVersion 15
targetSdkVersion 22
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile ('com.android.support:appcompat-v7:22.2.0')
compile 'com.squareup.okhttp:okhttp-urlconnection:2.0.0'
compile 'com.squareup.okhttp:okhttp:2.0.0'
compile 'com.jakewharton:butterknife:5.0.0'
compile 'com.squareup.retrofit:retrofit:1.7.1'
compile 'de.greenrobot:eventbus:2.2.1'
compile 'com.google.android.gms:play-services-gcm:7.8.0'
compile files('libs/commons-io-2.4.jar')
compile 'com.j256.ormlite:ormlite-android:4.48'
compile 'com.j256.ormlite:ormlite-core:4.48'
}
Run Code Online (Sandbox Code Playgroud)
以下就是一个例子
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
// compile project(':library') => this is the the libs having …Run Code Online (Sandbox Code Playgroud) 我们正在开发一个 android 项目,并希望开发两个可以协同工作的二进制文件:一个 UI 应用程序和一个 AAR 库后端。这个想法是 AAR 可能在未来与其他 UI 一起使用。
因此,我们有一名开发人员在从事 AAR 项目,另一名开发人员在从事 UI 项目。有没有办法同时调试两者;即,运行 UI+AAR 并在两者之间来回跟踪执行,在任一侧设置断点和监视等?
我在 .NET 中做了类似的事情,在一个“解决方案”中开发一个带有多个“项目”的 UI EXE+DLL 后端,一次调试整个事情;这是一种非常好的开发方式。有什么办法可以用 android studio 实现这一点吗?
谢谢。
我有一些.aar文件。我通过右键单击项目将它们添加到项目中,然后添加新模块,在那里我选择了Import .jar .aar Package.
这.aar在我的项目中添加了该文件,以及一个新创建的.gradle文件。
新的 Gradle 文件
configurations.maybeCreate("default")
artifacts.add("default", file('SDKTest-rel-1.01.aar'))
Run Code Online (Sandbox Code Playgroud)
现在当我尝试在我的build.gradle文件中添加这个文件时,它给了我错误消息
无法解决:SDKTest-rel-1.01。
我无法SDK在我的程序中使用这个类。
请指导我并告诉我添加和使用.aar文件的其他方法。
有时在库中我需要搜索方法名称或处理我正在寻找的方法.
在Android Studio中,有没有办法在jar,aar和maven导入的库中搜索单词?
它不必使用Android Studio,是否有工具可以在jar,aar,maven导入的库中搜索单词?
我有一个kotlin库FlowLayout lib as aar,
并希望在我的java代码(android)中使用它,但无法解决kotlin.Pair.
FlowLayoutManager layoutManager=new FlowLayoutManager(3, RecyclerView.HORIZONTAL, new FlowLayoutManager.Interface() {
@Override
public kotlin.Pair<Integer, Integer> getProportionalSizeForChild(int i) {
return null;
}
});
Run Code Online (Sandbox Code Playgroud)
我试过android.support.v4.util.Pair但不兼容.如何在java代码中使用kotlin lib及其对象依赖项?
我正在尝试将 Android 应用程序转换为 lib 模块,而不复制源代码。我做到了(修改了 build.gradle 文件),它会同步和构建,但是当我将生成的 AAR 文件的依赖项添加到另一个项目(我想在其中使用此库)时,构建失败并且资源链接失败。
我不明白为什么:
原始应用程序构建和运行
lib 模块(从应用程序转换而来)构建
使用该库中的 AAR 的项目不会构建,并在此 AAR 中发现错误。
例如,可能的错误之一是:
Android resource linking failed
error: resource style/TextAppearance.Design.Tab (aka bv.dev.aarlibtester:style/TextAppearance.Design.Tab) not found.
error: failed linking references.
Run Code Online (Sandbox Code Playgroud)
所以它说没有找到资源,并指向我在那个库中使用的依赖项(在这个例子中是design)
我创建了测试项目来演示这个简单的例子。
aar-res-app是使用design依赖项的简单应用程序项目
aar-res-lib 是从这个项目创建的库(转换)
aar-res-lib-tester 是使用该库的简单应用程序项目。
目前,我改名为库包不与应用程序包匹配,并采用jar代替aar。
我使用Gradle -> root -> Tasks -> Other -> createFullJarRelease.
结果在 Build > Intermediates > Full_jar > Release > CreateFullJarRelease > full.jar
我创建了两个 aar 库:com.example:test1:1.0.0 和 com.example:test2:1.0.0。我将这些库添加到我的主应用程序中,并且在构建 Android-Studio 后抛出错误:
Duplicate class com.example.utils.a found in modules classes.jar (com.example:test1:1.0.0) and classes.jar (com.example:test2:1.0.0)
我发现发生这个错误是因为两个库在同一个包(com.example.utils)中都有类,并且在混淆后 R8 创建了具有相同全名的类(a.class)(我在 aar 的 classes.jar 中看到了这个)。如果我在我的库的属性中禁用 R8,这个错误就会消失。
'a' 不是库类:混淆后所有库类名称保持不变,并且 a.class 被 R8 添加到包中。我阅读了 R8 文档,但没有发现有关此问题的任何信息。有没有办法解决这个问题,而无需在我的一个库中命名包?
我正在通过创建 aar 文件来编写 Android Studio 库。我将此文件安装在专用网络的 maven 存储库上。我现在正在尝试让用户只知道类名称和方法名称,在 Stackoverflow库混淆中使用 proguard的这个问题的帮助下,但没有成功。我成功地只对几个类名和构造函数名这样做,而方法名混淆为字母(a(),b()......)。现在,当我在 build.gradle 文件中本地获取库时,一切正常
implementation(files('C:\\Users\\User\\AndroidStudioProjects\\android-app2\\app\\build\\outputs\\aar\\app-open.aar'))
Run Code Online (Sandbox Code Playgroud)
但不是那样
api('xx.yyy.sdk:app:1.0.0@aar') { transitive = true }
Run Code Online (Sandbox Code Playgroud)
第一个包括显示所有类及其名称和方法名,而第二个只显示几个类名和构造函数名称,正如我之前写的。
项目的 build.gradle 文件
buildscript {
dependencies {
classpath 'com.android.tools.build:gradle:3.4.1'
}
}
Run Code Online (Sandbox Code Playgroud)
保护文件
#
# This ProGuard configuration file illustrates how to process a program
# library, such that it remains usable as a library.
# Usage:
# java -jar proguard.jar @library.pro
#
# Specify the input jars, output jars, and library jars.
# In this case, the …Run Code Online (Sandbox Code Playgroud) 我使用 Kotlin v1.4.0 编译并发布了一个 AAR 库。当我在另一个项目(使用 Kotlin v1.2.71)中包含这个库时,它拒绝编译并返回此错误:
.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib-common/1.4.0/1c752cce0ead8d504ccc88a4fed6471fd83ab0dd/kotlin-stdlib-common-1.4.0.jar!/META-INF/kotlin-stdlib-common.kotlin_module: Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.4.0, expected version is 1.1.11.
问题: