Android SDK/Maven 配置问题

Android SDK/Maven configuration issues

我正在尝试编译一个 android 项目以使用 maven 生成 .apk(我没有使用 Android Studio,我正在使用 IntelliJ idea)

1- 我已经下载了这个 line command tool,我猜它是 SDK 管理器,我已经解压到一个名为 Android 的文件夹中,解压结果生成一个名为 tools 的文件夹。

2- 我执行 /Android/tools/android.sh ,它显示 SDK Manager 并开始下载:

下载完成后,它会在 /Android:

上创建新文件夹(我只创建 "tools" 文件夹和 "android-keystore")

3- 我在 ~/.bashrc 中编辑 ANDROID 路径如下:

export ANDROID_HOME='/home/myUser/Android'
export PATH=$PATH:$ANDROID_HOME/tools
export PATH=$PATH:$ANDROID_HOME/platform-tools

问题 1 : ¿ANDROID_HOME 是否指向 SDK 路径?

当我尝试为我的 android 项目创建 'mvn clean install' 时,出现此错误:

[INFO] /usr/lib/jvm/java-7-oracle/jre/bin/java [-Xmx1024M, -jar, /home/nb022/Android/build-tools/22.0.1/lib/dx.jar, --dex, --output=/home/nb022/workspace/cl.claro/android/antica-sessmobile-android2/target/classes.dex, /home/nb022/.m2/repository/com/google/code/gson/gson/2.2.4/gson-2.2.4.jar, /home/nb022/.m2/repository/commons-logging/commons-logging/1.1.1/commons-logging-1.1.1.jar, /home/nb022/.m2/repository/antica/external/cordova/3.7.2/cordova-3.7.2.jar, /home/nb022/workspace/cl.claro/android/antica-sessmobile-android2/target/classes, /home/nb022/.m2/repository/commons-pool/commons-pool/1.3/commons-pool-1.3.jar, /home/nb022/.m2/repository/antica/base/antica-base-commons/4.16/antica-base-commons-4.16-jdk6.jar, /home/nb022/.m2/repository/commons-lang/commons-lang/2.4/commons-lang-2.4.jar, /home/nb022/.m2/repository/ch/acra/acra/4.5.0/acra-4.5.0.jar, /home/nb022/.m2/repository/de/mindpipe/android/android-logging-log4j/1.0.3/android-logging-log4j-1.0.3.jar, /home/nb022/.m2/repository/com/google/android/android/4.1.1.4/android-4.1.1.4.jar, /home/nb022/.m2/repository/log4j/log4j/1.2.17/log4j-1.2.17.jar, /home/nb022/.m2/repository/commons-collections/commons-collections/3.2.1/commons-collections-3.2.1.jar, /home/nb022/.m2/repository/org/apache/velocity/velocity/1.7/velocity-1.7.jar, /home/nb022/.m2/repository/org/json/json/20080701/json-20080701.jar, /home/nb022/.m2/repository/antica/core/antica-core-mobile/4.75/antica-core-mobile-4.75.jar, /home/nb022/.m2/repository/xpp3/xpp3/1.1.4c/xpp3-1.1.4c.jar, /home/nb022/.m2/repository/org/khronos/opengl-api/gl1.1-android-2.1_r1/opengl-api-gl1.1-android-2.1_r1.jar, /home/nb022/.m2/repository/xerces/xmlParserAPIs/2.6.2/xmlParserAPIs-2.6.2.jar]
[INFO] warning: Ignoring InnerClasses attribute for an anonymous inner class
[INFO] (org.apache.commons.logging.impl.LogFactoryImpl) that doesn't come with an
[INFO] associated EnclosingMethod attribute. This class was probably produced by a
[INFO] compiler that did not target the modern .class file format. The recommended
[INFO] solution is to recompile the class from source, using an up-to-date compiler
[INFO] and without specifying any "-target" type options. The consequence of ignoring
[INFO] this warning is that reflective operations on this class will incorrectly
[INFO] indicate that it is *not* an inner class.
[INFO] warning: Ignoring InnerClasses attribute for an anonymous inner class
[INFO] (org.apache.commons.logging.impl.LogFactoryImpl) that doesn't come with an
[INFO] associated EnclosingMethod attribute. This class was probably produced by a
[INFO] compiler that did not target the modern .class file format. The recommended
[INFO] solution is to recompile the class from source, using an up-to-date compiler
[INFO] and without specifying any "-target" type options. The consequence of ignoring
[INFO] this warning is that reflective operations on this class will incorrectly
[INFO] indicate that it is *not* an inner class.
[INFO] warning: Ignoring InnerClasses attribute for an anonymous inner class
[INFO] (org.apache.commons.logging.impl.LogFactoryImpl) that doesn't come with an
[INFO] associated EnclosingMethod attribute. This class was probably produced by a
[INFO] compiler that did not target the modern .class file format. The recommended
[INFO] solution is to recompile the class from source, using an up-to-date compiler
[INFO] and without specifying any "-target" type options. The consequence of ignoring
[INFO] this warning is that reflective operations on this class will incorrectly
[INFO] indicate that it is *not* an inner class.
[INFO] warning: Ignoring InnerClasses attribute for an anonymous inner class
[INFO] (org.apache.commons.logging.impl.SimpleLog) that doesn't come with an
[INFO] associated EnclosingMethod attribute. This class was probably produced by a
[INFO] compiler that did not target the modern .class file format. The recommended
[INFO] solution is to recompile the class from source, using an up-to-date compiler
[INFO] and without specifying any "-target" type options. The consequence of ignoring
[INFO] this warning is that reflective operations on this class will incorrectly
[INFO] indicate that it is *not* an inner class.
[INFO] warning: Ignoring InnerClasses attribute for an anonymous inner class
[INFO] (org.apache.commons.logging.impl.WeakHashtable) that doesn't come with an
[INFO] associated EnclosingMethod attribute. This class was probably produced by a
[INFO] compiler that did not target the modern .class file format. The recommended
[INFO] solution is to recompile the class from source, using an up-to-date compiler
[INFO] and without specifying any "-target" type options. The consequence of ignoring
[INFO] this warning is that reflective operations on this class will incorrectly
....

NFO] and without specifying any "-target" type options. The consequence of ignoring
[INFO] this warning is that reflective operations on this class will incorrectly
[INFO] indicate that it is *not* an inner class.
[INFO] 
[INFO] trouble processing "javax/xml/namespace/QName.class":
[INFO] 
[INFO] Ill-advised or mistaken usage of a core class (java.* or javax.*)
[INFO] when not building a core library.
[INFO] 
[INFO] This is often due to inadvertently including a core library file
[INFO] in your application's project, when using an IDE (such as
[INFO] Eclipse). If you are sure you're not intentionally defining a
[INFO] core class, then this is the most likely explanation of what's
[INFO] going on.
[INFO] 
[INFO] However, you might actually be trying to define a class in a core
[INFO] namespace, the source of which you may have taken, for example,
[INFO] from a non-Android virtual machine project. This will most
[INFO] assuredly not work. At a minimum, it jeopardizes the
[INFO] compatibility of your app with future versions of the platform.
[INFO] It is also often of questionable legality.
[INFO] 
[INFO] If you really intend to build a core library -- which is only
[INFO] appropriate as part of creating a full virtual machine
[INFO] distribution, as opposed to compiling an application -- then use
[INFO] the "--core-library" option to suppress this error message.
[INFO] 
[INFO] If you go ahead and use "--core-library" but are in fact
[INFO] building an application, then be forewarned that your application
[INFO] will still fail to build or run, at some point. Please be
[INFO] prepared for angry customers who find, for example, that your
[INFO] application ceases to function once they upgrade their operating
[INFO] system. You will be to blame for this problem.
[INFO] 
[INFO] If you are legitimately using some code that happens to be in a
[INFO] core package, then the easiest safe alternative you have is to
[INFO] repackage that code. That is, move the classes in question into
[INFO] your own package namespace. This means that they will never be in
[INFO] conflict with core system classes. JarJar is a tool that may help
[INFO] you in this endeavor. If you find that you cannot do this, then
[INFO] that is an indication that the path you are on will ultimately
[INFO] lead to pain, suffering, grief, and lamentation.
[INFO] 
[INFO] 1 error; aborting
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 19.901s
[INFO] Finished at: Fri Feb 24 14:46:58 CLT 2017
[INFO] Final Memory: 22M/218M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal com.jayway.maven.plugins.android.generation2:android-maven-plugin:3.6.1:dex (default-dex) on project antica-sessmobile-android2: MojoExecutionException: ANDROID-040-001: Could not execute: Command = /bin/sh -c cd /home/nb022/workspace/cl.claro/android/antica-sessmobile-android2 && /usr/lib/jvm/java-7-oracle/jre/bin/java -Xmx1024M -jar /home/nb022/Android/build-tools/22.0.1/lib/dx.jar --dex --output=/home/nb022/workspace/cl.claro/android/antica-sessmobile-android2/target/classes.dex /home/nb022/.m2/repository/com/google/code/gson/gson/2.2.4/gson-2.2.4.jar /home/nb022/.m2/repository/commons-logging/commons-logging/1.1.1/commons-logging-1.1.1.jar /home/nb022/.m2/repository/antica/external/cordova/3.7.2/cordova-3.7.2.jar /home/nb022/workspace/cl.claro/android/antica-sessmobile-android2/target/classes /home/nb022/.m2/repository/commons-pool/commons-pool/1.3/commons-pool-1.3.jar /home/nb022/.m2/repository/antica/base/antica-base-commons/4.16/antica-base-commons-4.16-jdk6.jar /home/nb022/.m2/repository/commons-lang/commons-lang/2.4/commons-lang-2.4.jar /home/nb022/.m2/repository/ch/acra/acra/4.5.0/acra-4.5.0.jar /home/nb022/.m2/repository/de/mindpipe/android/android-logging-log4j/1.0.3/android-logging-log4j-1.0.3.jar /home/nb022/.m2/repository/com/google/android/android/4.1.1.4/android-4.1.1.4.jar /home/nb022/.m2/repository/log4j/log4j/1.2.17/log4j-1.2.17.jar /home/nb022/.m2/repository/commons-collections/commons-collections/3.2.1/commons-collections-3.2.1.jar /home/nb022/.m2/repository/org/apache/velocity/velocity/1.7/velocity-1.7.jar /home/nb022/.m2/repository/org/json/json/20080701/json-20080701.jar /home/nb022/.m2/repository/antica/core/antica-core-mobile/4.75/antica-core-mobile-4.75.jar /home/nb022/.m2/repository/xpp3/xpp3/1.1.4c/xpp3-1.1.4c.jar /home/nb022/.m2/repository/org/khronos/opengl-api/gl1.1-android-2.1_r1/opengl-api-gl1.1-android-2.1_r1.jar /home/nb022/.m2/repository/xerces/xmlParserAPIs/2.6.2/xmlParserAPIs-2.6.2.jar, Result = 1 -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.

项目的 POM 包含此插件:

    <plugin>
            <groupId>com.jayway.maven.plugins.android.generation2</groupId>
            <artifactId>android-maven-plugin</artifactId>
            <executions>
              <execution>
                <id>manifest-version</id>
                <goals>
                  <goal>manifest-update</goal>
                </goals>
                <configuration>
                  <manifest>
                    <versionCodeAutoIncrement>false</versionCodeAutoIncrement>
                    <versionName>${project.version}</versionName>
                  </manifest>
                </configuration>
              </execution>
            </executions>
            <configuration>
              <assetsDirectory>assets</assetsDirectory>
              <resourceDirectory>res</resourceDirectory>
              <sdk>
                <platform>16</platform>
              </sdk>
            </configuration>
            <extensions>true</extensions>
            <version>3.6.1</version>
          </plugin>

这是项目清单 (android:minSdkVersion="8" android:targetSdkVersion="16"):

<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:hardwareAccelerated="true" android:installLocation="internalOnly" android:versionCode="305" android:versionName="2.2.4" android:windowSoftInputMode="adjustPan" package="cl.myApp">

    <supports-screens android:anyDensity="true" android:largeScreens="true" android:normalScreens="true" android:resizeable="true" android:smallScreens="true" android:xlargeScreens="true"/>

    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.GET_TASKS"/>
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.READ_PHONE_STATE"/>
    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.READ_PHONE_STATE"/>

    <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="16"/>

    <application android:allowBackup="true" android:hardwareAccelerated="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:name="com.myApp.SessMobileApplication">

        <activity android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale" android:excludeFromRecents="true" android:label="@string/app_name" android:name="com.myApp.ClaroSessMobile" android:process=":core" android:theme="@android:style/Theme.Black.NoTitleBar">
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>

        <activity android:label="@string/app_name" android:launchMode="singleInstance" android:name="cl.MyOrg.core.MyApp.activity.SessMobileDialog" android:process=":core" android:theme="@android:style/Theme.Dialog"/>

        <activity android:name="com.myApp.SplashIntent"/>
        <activity android:name="com.myApp.ErrorIntent"/>
        <activity android:name="com.myApp.ErrorNetworkIntent"/>


        <receiver android:enabled="true" android:exported="true" android:name="cl.MyOrg.core.MyApp.receiver.SessMobileActionReceiver" android:process=":core">
            <intent-filter>
                <action android:name="android.intent.action.BOOT_COMPLETED"/>
                <action android:name="android.intent.action.EXTERNAL_APPLICATIONS_AVAILABLE"/>
            </intent-filter>
            <intent-filter>
                <action android:name="android.intent.action.PACKAGE_REPLACED"/>
                <data android:scheme="package"/>
            </intent-filter>
        </receiver>

        <service android:name="cl.MyOrg.core.MyApp.services.SessMobileCore" android:process=":core"/>

        <service android:name="cl.MyOrg.core.MyApp.services.SessMobileNotifier" android:process=":core">

        </service>
    </application>
</manifest>

希望你们能帮我解决这个错误。目前我正在使用:

阿帕奇行家 3.0.5 Maven 主页:/usr/local/apache-maven-3.0.5 Java 版本:1.7.0_80,供应商:Oracle Corporation Java 家:/usr/lib/jvm/java-7-oracle/jre 默认语言环境:es_CL,平台编码:UTF-8 OS 名称:"linux",版本:“4.4.0-21-generic”,架构:"amd64",系列:"unix"

IntelliJ IDEA。

我解决了问题,将 buildTools (Android/build-tools) 的版本从 25 降级到 23.0.3 并将依赖范围设置为 provided

    <dependency>
          <groupId>com.google.android</groupId>
          <artifactId>android</artifactId>
          <version>4.1.1.4</version>
          <scope>provided</scope>
    </dependency>