将外部AAR嵌入我的AAR时出错

时间:2017-01-23 11:20:55

标签: android gradle android-gradle

我们向客户发送aar,其内部依赖于来自第三方供应商的2 aar。要将这些嵌入到我们的项目中,我们一直在使用以下库: https://github.com/adwiv/android-fat-aar

最新升级到gradle 2.14.1后,我们在组装发布aar文件时遇到以下错误。:

C:\Mobile 3.7 Android\testproj\build\generated\source\r\release\com\eye\R.java:1264: error: cannot find symbol
public static int Theme_popupMenuStyle = com.company.mobile.android.sdk.activity.R.styleable.Theme_popupMenuStyle;
^
symbol: variable Theme_popupMenuStyle
location: class styleable
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
100 errors
:testproj:compileReleaseJavaWithJavac FAILED

FAILURE: Build failed with an exception.

What went wrong:
Execution failed for task ':testproj:compileReleaseJavaWithJavac'.
Compilation failed; see the compiler error output for details.
Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED

另一个观察,我们试图嵌入2个aar,其中一个没有R.java文件,当我打开爆炸的AAR时我看到了这个。也许这会引起一些问题。

以下是我的gradle文件中嵌入了这些依赖项的内容:

/Creation of fat-aar is based on this project: https://github.com/adwiv/android-fat-aar
apply from: 'fat-aar.gradle'
dependencies {
  embedded 'com.eye.version@aar'
  embedded 'com.eye.versioninterface@aar'
}

下面是构建失败的fat-aar.gradle部分:

task generateRJava << {
  println "Running FAT-AAR Task :generateRJava"

  // Now generate the R.java file for each embedded dependency
  def libPackageName = new 

XmlParser().parse(android.sourceSets.main.manifest.srcFile).@package

  embeddedAarDirs.each { aarPath ->

def aarManifest = new XmlParser().parse(file("$aarPath/AndroidManifest.xml"));
def aarPackageName = aarManifest.@package
String packagePath = aarPackageName.replace('.', '/')

// Generate the R.java file and map to current project's R.java
// This will recreate the class file
def rTxt = file("$aarPath/R.txt")
def rMap = new ConfigObject()

if (rTxt.exists()) {
  rTxt.eachLine {
    line ->
      //noinspection GroovyUnusedAssignment
      def (type, subclass, name, value) = line.tokenize(' ')
      rMap[subclass].putAt(name, type)
  }
}

def sb = "package $aarPackageName;" << '\n' << '\n'
sb << 'public final class R {' << '\n'

rMap.each {
  subclass, values ->
    sb << "  public static final class $subclass {" << '\n'
    values.each {
      name, type ->
        sb << "    public static $type $name = ${libPackageName}.R.${subclass}.${name};" << '\n'
    }
    sb << "    }" << '\n'
}

sb << '}' << '\n'

mkdir("$generated_rsrc_dir/$packagePath")
file("$generated_rsrc_dir/$packagePath/R.java").write(sb.toString())

embeddedRClasses += "$packagePath/R.class"
embeddedRClasses += "$packagePath/R\$*.class"


}
}

有人可以帮忙吗?

0 个答案:

没有答案