簡體   English   中英

沒有找到Android studio aar文件錯誤類

[英]Android studio aar file error class not found

當我嘗試在其他項目中使用導出的android庫項目(aar格式)時。 我收到以下錯誤。

> "Could not find class 'com.manish.core.helper.RegistrationHelper$1'" 
> "Could not find class 'com.manish.core.helper.RegistrationHelper$2'"
> "Could not find class 'com.manish.core.helper.RegistrationHelper$3'"
> "Could not find class 'com.manish.core.helper.RegistrationHelper$4'"

在aar文件中有一個文件“classes.jar”,它包含所有類文件,但我不明白錯誤的原因。

我正在使用android studio在build目錄中生成的aar文件。 我還在gradle文件中添加了apply plugin: 'com.android.library'

所有這些錯誤僅適用於匿名和靜態類。

我的gradle文件:

apply plugin: 'com.manish.application'

android {
    compileSdkVersion 22
    buildToolsVersion "23.0.0"

    defaultConfig {
        applicationId "com.manish.test"
        minSdkVersion 10
        targetSdkVersion 22
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

repositories {
    mavenCentral()
}


dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile 'com.android.support:appcompat-v7:22.2.0'
    compile 'junit:junit:4.12'
    compile(name:'somerandomlibrary-debug', ext:'aar')
}

repositories{
    flatDir{
        dirs 'libs'
    }
}

問題是, aar文件不包含嵌套依賴項,並且沒有描述庫使用的依賴項的POM文件。

如果要使用flatDir repo導入aar文件 ,則還必須在項目中指定依賴項。 你應該使用maven存儲庫 例如: maven-publish

一個更簡單的解決方案是,將以下行添加到“aar”項目中的build.gradle:

task createPom {
    apply plugin: 'maven'
    description "Generates pom.xml"
    pom {
        project {
            groupId 'com.example'
            artifactId 'example'
            version '0.0.1-SNAPSHOT'
            packaging 'aar'
        }
    }.withXml {
        def dependenciesNode = asNode().appendNode('dependencies')

        configurations.compile.allDependencies.each { dependency ->
            def dependencyNode = dependenciesNode.appendNode('dependency')
            dependencyNode.appendNode('groupId', dependency.group)
            dependencyNode.appendNode('artifactId', dependency.name)
            dependencyNode.appendNode('version', dependency.version)
        }
    }.writeTo("$buildDir/pom.xml")
}

您可以在基於aar的應用程序中使用生成的POM文件進行依賴項注入。

這不是一個好習慣,但如果你真的需要它,你可以使用nested dependencies ,就像這樣

depenencies {
    ...

    compile (name:'somerandomlibrary-debug', ext:'aar') {
        dependencies {
            compile 'com.some:dependency:9.1.1'
            ...
        }
    }
}

要使用aar文件,你必須在build.gradle somenthing中使用,如:

repositories{
      flatDir{
              dirs 'libs'
       }
 }

通過這種方式,您可以在libs文件夾中使用aar文件。

然后你必須使用以下方法添加依賴項:

dependencies {
   compile(name:'nameOfYourAARFileWithoutExtension', ext:'aar')
 }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM