java - 如何将 .aar 包的所有内容转换为 .jar 包?
问题描述
我正在尝试根据上面的标题将 .aar 包转换为 .jar 包。我已经尝试了几个程序(包括这里提到的那些),但都没有成功。看来需要将包中的所有内容(包括资源、清单等)都转换成.jar。
这样做的原因是我需要将 .jar 文件与我的库一起发布到工件存储库中,因为 .aar 在组装过程中在“libs /”中引用它时会出现以下错误:
Execution failed for task ':integration-lib:bundleReleaseAar'.
> Direct local .aar file dependencies are not supported when building an AAR. The resulting AAR would be broken because the classes and Android resources from any local .aar file dependencies would not be packaged in the resulting AAR.
Previous versions of the Android Gradle Plugin produce broken AARs in this case too (despite not throwing this error). The following direct local .aar file dependencies of the :integration-lib project caused this error: /Users/thomas/Projetos/mobile-integration-lib/integration-lib/libs/PPCompAndroid-v1.32.aar
我还尝试通过使用 .jar/.aar 文件创建一个新模块并在库 gradle 中引用它来导入它,但它没有部署在工件存储库中。
我的 Gradle 库:
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'com.jfrog.artifactory'
apply plugin: 'maven-publish'
def application = new Application()
class Application {
def packageName = 'com.soufan.integration-lib'
def versionMajor = 0
def versionMinor = 0
def versionPatch = 27
def versionName() {
return (versionPatch > 0 ? "${versionMajor}.${versionMinor}.${versionPatch}" : "${versionMajor}.${versionMinor}")
}
def static gitVersion() {
def process = ['/bin/bash', '-c', 'git rev-list HEAD | wc -l | xargs'].execute()
return process.text.toInteger()
}
}
android {
compileSdkVersion 30
buildToolsVersion "30.0.0"
defaultConfig {
minSdkVersion 22
targetSdkVersion 30
versionCode application.gitVersion()
versionName application.versionName()
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles "consumer-rules.pro"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
publishing {
publications {
aar(MavenPublication) {
groupId application.getPackageName()
version application.versionName()
artifactId project.getName()
artifact("$buildDir/outputs/aar/${project.getName()}-release.aar")
pom.withXml {
def dependenciesNode = asNode().appendNode('dependencies')
configurations.compile.allDependencies.each { dependency ->
if (dependency.group != null) {
def dependencyNode = dependenciesNode.appendNode('dependency')
dependencyNode.appendNode('groupId', dependency.group)
dependencyNode.appendNode('artifactId', dependency.name)
dependencyNode.appendNode('version', dependency.version)
}
}
}
}
}
}
artifactory {
contextUrl = URL_DEPLOY
publish {
repository {
repoKey = DEPLOY_REPO_KEY
username = USER_NAME
password = API_KEY
}
defaults {
publications('aar')
publishArtifacts = true
properties = ['qa.level': 'basic', 'dev.team': 'core']
publishPom = true
}
}
}
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'androidx.core:core-ktx:1.3.0'
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
implementation 'com.journeyapps:zxing-android-embedded:3.6.0'
implementation 'com.squareup.okhttp3:okhttp:4.0.1'
// Dependencies
implementation files('libs/NeptuneLiteApi_V2.04.00_20180329.jar')
implementation files('libs/PPCompAndroid-v1.32.aar')
implementation files('libs/libposdigital-1.5.1-4-release.aar')
implementation files('libs/zoop-emv-connect-pax-a920-pos_0.10.jar')
}
我的项目摇篮:
buildscript {
ext.kotlin_version = "1.3.72"
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:4.0.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "org.jfrog.buildinfo:build-info-extractor-gradle:4.10.0"
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
解决方案
推荐阅读
- docker - GitLab CI,从 docker dind 连接到 Elastic Search 服务
- angular - 在 AWS lambda 函数执行后通知客户端
- ios - 查询 Firebase 实时数据库 Swift
- python - 我想在 Django 中使用模板标签在相关用户的个人资料中显示用户的产品
- javascript - 将 Pug 列和行导出为 CSV
- intellij-idea - PyCharm DB Navigator:如何修复“没有这样的文件或目录”
- java - 在“org.springframework.webflow.engine.impl.RequestControlContextImpl”类型的对象上找不到属性或字段“httpServletRequest”
- javascript - 动态src ------ js >>> to html
- winapi - AnimateWindow() 在高 dpi 上错误地绘制背景 (Win10)
- elixir - 当 2 个库共享相同的依赖项并需要不同的版本时,混合 deps 错误