java—如何将.aar包的所有内容转换为.jar包?

pbpqsu0x  于 2021-07-06  发布在  Java
关注(0)|答案(0)|浏览(248)

我正在尝试根据上面的标题将.aar包转换为.jar包。我试过几个程序(包括这里提到的),但都没有成功。似乎有必要将包的所有内容(包括资源、清单等)转换为.jar。
原因是我需要将.jar文件与我的库一起发布到artifactory存储库中,因为.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中引用它来导入它,但它没有部署在artifactory存储库中。
我的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')
}

我的gradle项目:

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
}

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题