简体   繁体   English

Ant构建不包括Android支持库jar

[英]Ant build does not include Android support library jar

I have a cmake script for cross compiling our code. 我有一个用于交叉编译代码的cmake脚本。 To compile for Android we use Ant which runs cmake for the native parts. 为了针对Android进行编译,我们使用Ant为本机部分运行cmake。 Ant handles the Android/java part. Ant处理Android / java部分。 Since we have imports like import android.support.v4.app.ActivityCompat; 由于我们已经导入了import android.support.v4.app.ActivityCompat; on the java side I took the support library jar at /my/sdk/folder/extras/android/m2repository/com/android/support/support-v4/24.0.0/support-v4-24.0.0-sources.jar and stuck it in my libs folder. 在Java方面,我在/my/sdk/folder/extras/android/m2repository/com/android/support/support-v4/24.0.0/support-v4-24.0.0-sources.jar和将其粘贴在我的libs文件夹中。 I am pretty sure this has worked for older SDK versions before, but now it does not work. 我可以肯定,以前它可以用于较早的SDK版本,但现在不起作用。 (It also seems that the filename of the jar has changed, don't know if it matters in any way.) (似乎jar的文件名也已更改,不知道它是否有任何关系。)

The problem is that, even though I have the jar in my libs folder, I still get loads of errors like error: package android.support.v4.content does not exist when building the code. 问题是,即使我的libs文件夹中有jar文件,我仍然会收到很多错误,如error: package android.support.v4.content does not exist构建代码时, error: package android.support.v4.content does not exist Shouldn't it be as easy as to drop the support library jar in the libs folder and off we go? 难道不如将支持库jar放到libs文件夹中然后离开我们一样容易吗? Before including the support libraries everything compiled fine. 在包括支持库之前,所有内容都可以很好地编译。

What can I possibly be doing wrong here? 我在这里可能做错了什么? What other things can I try/check? 我还能尝试/检查哪些其他东西?

What have I tried: 我尝试了什么:

  1. Unzipping the jar to see that the Android files are there. 解压缩jar文件,查看其中是否有Android文件。 They are, and everything seems to be in order. 他们是,一切似乎都井井有条。
  2. Take the unzipped files from the jar and add it to my src folder so that, in addition to my own files, we have src/com/android/support/v4/... . 从jar中提取解压缩的文件,并将其添加到我的src文件夹中,这样,除了我自己的文件外,我们还有src/com/android/support/v4/... Most of the support library compiled, but there were other errors. 大多数支持库都已编译,但是还有其他错误。 This is really beside the point, since the inclusion of a jar should be simple. 这实际上是无关紧要的,因为添加一个罐子应该很简单。
  3. Force Ant to include the jar directly by using <path> with <fileset> , see the attempt in build.xml below. 通过将<path><fileset>结合使用来强制Ant直接将jar包含在内,请参见下面的build.xml中的尝试。
  4. Various other small things. 其他各种小东西。

build.xml build.xml

<?xml version="1.0" encoding="UTF-8"?>

<project name="myApp" default="debug" xmlns:if="ant:if" xmlns:unless="ant:unless">
    <property environment="env" />
    <path id="sdk.dir_path">
        <pathelement path="${env.ANDROID_SDK}" />
    </path>
    <path id="ndk.dir_path">
        <pathelement path="${env.ANDROID_NDK}" />
    </path>
    <pathconvert targetos="unix" property="sdk.dir" refid="sdk.dir_path"/>
    <pathconvert targetos="unix" property="ndk.dir" refid="ndk.dir_path"/>

    <property file="ant.properties" />
    <loadproperties srcFile="local.properties" />
    <loadproperties srcFile="project.properties" />

    <!-- Attempting to force inclusion of jar. Does not help. -->
    <property name="project.lib.dir" value="${basedir}/libs"/>
    <path id="lib.path">
        <fileset dir="${project.lib.dir}" includes="support-v4-24.0.0-sources.jar" />
    </path>

    <fail
        message="sdk.dir is missing. Make sure to generate local.properties using 'android update project'."
        unless="sdk.dir"
        />

    <target name="clean" depends="android_rules.clean">
        <delete dir="obj"/>
        <delete dir="libs/x86"/>
        <delete dir="libs/armeabi-v7a"/>
        <delete dir="build_x86"/>
        <delete dir="build_armeabi-v7a"/>
    </target>


    <!-- Not relevant -->
    <target name="build-jni">
        <!-- Snip -->
    </target>

    <target name="-pre-build" depends="build-jni">
    </target>

    <!-- Include Android build.xml -->
    <import file="${sdk.dir}/tools/ant/build.xml"/>

</project>

Folder structure 资料夹结构

.
├── AndroidManifest.xml
├── ant.properties
├── build_cmake.xml
├── build.xml
├── jni
│   ├── Android.mk
│   └── Application.mk
├── libs
│   └── support-v4-24.0.0-sources.jar
├── local.properties
├── project.properties
├── README.txt
├── res
│   └── values
│       └── strings.xml
└── src
    └── com
        └── mycompany
            └── myApp
                └── myApp.java

8 directories, 12 files

There isn't really anything special about the other files - they contain just normal stuff. 其他文件确实没有什么特别的-它们只包含普通文件。 I'll post them here anyway in case I have missed something silly. 无论如何我都会把它们张贴在这里,以防我错过了一些愚蠢的事情。

AndroidManifest.xml AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>

<manifest
    xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.mycompany.myApp"
    android:versionCode="1"
    android:versionName="1.0.0" >

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

    <uses-permission android:name="android.permission.INTERNET"/>

    <uses-feature
        android:glEsVersion="0x00020000"
        android:required="true" />

    <application
        android:label="@string/app_name"
        android:debuggable="true">

        <activity
            android:name="com.mycompany.myApp.myApp"
            android:label="@string/app_name"
            android:screenOrientation="portrait">
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>

    </application>

</manifest>

project.properties project.properties

target=android-15

local.properties local.properties

Empty file

ant.properties ant.properties

// An attempt to force Ant to include libs folder
jar.libs.dir=libs

jni/Android.mk jni / Android.mk

// Not really used, cmake sets target platform.
APP_ABI := all

jni/Application.mk jni / Application.mk

// Not really used, cmake sets target platform.
APP_ABI := x86

strings.xml is not relevant and the only thing we need to know from myApp.java is that it has the include statements above to use the support libraries. strings.xmlmyApp.java的,从myApp.java我们唯一需要知道的是,它具有上面的include语句才能使用支持库。 build_cmake.xml is just another ant script called from build.xml to run cmake . build_cmake.xml只是从build.xml调用的另一个运行cmake蚂蚁脚本。

I took the support library jar at /my/sdk/folder/extras/android/m2repository/com/android/support/support-v4/24.0.0/support-v4-24.0.0-sources.jar and stuck it in my libs folder 我在/my/sdk/folder/extras/android/m2repository/com/android/support/support-v4/24.0.0/support-v4-24.0.0-sources.jar中获取了支持库jar并将其粘贴在我的libs文件夹

Unless you somehow hacked the build process to compile Java source code out of a JAR file, that will not work. 除非您以某种方式破解了从JAR文件中编译Java源代码的构建过程,否则将无法正常工作。

Shouldn't it be as easy as to drop the support library jar in the libs folder and off we go? 难道不如将支持库jar放到libs文件夹中然后离开我们一样容易吗?

There is no "support library jar". 没有“支持库jar”。 support-v4 has been distributed as an AAR, for use in AAR-aware build tools (Gradle, Maven), since 20.0.0 , about two years ago. 从大约两年前的20.0.0support-v4已作为AAR分发,用于支持AAR的构建工具(Gradle,Maven)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM