Ant 忽略 Android 打包中的 .so 库

发布于 2025-01-13 04:32:54 字数 3046 浏览 1 评论 0原文

我用 NDK 在 C++ 中构建了一个 lib.so,我如何告诉 Ant 分解 .so 和 .so? .a libs 放入包中,它会生成一个 apk 文件,但它生成的 libs 目录是空的...

我读到需要有一个 armabi 文件夹,我将 libs 放在 arm64-v8a 中,但仍然没有任何改变。

谢谢

project.properties
target=android-29
has.keystore=true
key.store=C:/path
key.alias=mykey
source.dir=.
gen.dir=gen
resource.dir=res 
asset.dir=assets
external.libs.dir=.
out.dir=Package/bin
key.store.password=pw
key.alias.password=pw

build.xml
<?xml version="1.0" encoding="UTF-8"?>
<project name="project" default="help">
 
<property file="ant.properties" />

<property environment="env" />
<condition property="sdk.dir" value="${env.ANDROID_HOME}">
    <isset property="env.ANDROID_HOME" />
</condition>

<loadproperties srcFile="project.properties" />

<!-- quick check on sdk.dir -->
<fail message="sdk.dir is missing. Make sure ANDROID_HOME 
environment variable is correctly set."
        unless="sdk.dir"/>

<import file="custom_rules.xml" optional="true" />

<!-- version-tag: 1 -->
<import file="${sdk.dir}/tools/ant/build.xml" />

<target name="-pre-compile">
  <path id="project.all.jars.path">
    <path path="${toString:project.all.jars.path}"/>
    <fileset dir="${jar.libs.dir}">
      <include name="*.jar"/>
    </fileset>
  </path>
</target>
</project>

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

<target name="clean">
    <delete dir="Package"/>
    <delete dir="gen"/>
    <delete dir="libs"/>
</target>

<xmlproperty file="AndroidManifest.xml" prefix="custom" 
collapseAttributes="true" />
<condition property="version.code" value="${env.BUILD_NUMBER}" 
else="${custom.manifest.android:versionCode}">
    <isset property="env.BUILD_NUMBER" />
</condition>
<property name="version.name" 
value="${custom.manifest.android:versionName}.${version.code}" />

 <target name="-set-mode-check" depends="android_rules.-set-mode- 
   check, -release-prompt-for-password, -set-apk-filenames" />

 <target name="-set-apk-filenames">
    <condition property="custom.tag" value="release">
        <contains string="${ant.project.invoked-targets}" 
substring="release" />
    </condition>
    <condition property="custom.tag" value="debug">
        <contains string="${ant.project.invoked-targets}" 
substring="debug" />
    </condition>
    <condition property="custom.tag" value="instrumented">
        <contains string="${ant.project.invoked-targets}" 
substring="instrument" />
    </condition>
    <condition property="custom.suffix" value="unsigned" 
else="unaligned">
        <contains string="${ant.project.invoked-targets}" 
    substring="release" />
    </condition>
    </target>
</project>

一定有办法做到这一点,Visual Studio 使用 Ant 来打包 .so & 。 .a 文件适用于 ARM64,但它们有一些配方中间步骤,仅保存所有 lib 资源的路径。

谢谢

I built a lib.so in C++ with NDK, how do I tell Ant to factor .so & .a libs into the package, it makes an apk file but the libs directory it makes is empty...

I read that there needs to be an armabi folder, I put the libs in arm64-v8a but nothing changed still.

Thanks

project.properties
target=android-29
has.keystore=true
key.store=C:/path
key.alias=mykey
source.dir=.
gen.dir=gen
resource.dir=res 
asset.dir=assets
external.libs.dir=.
out.dir=Package/bin
key.store.password=pw
key.alias.password=pw

build.xml
<?xml version="1.0" encoding="UTF-8"?>
<project name="project" default="help">
 
<property file="ant.properties" />

<property environment="env" />
<condition property="sdk.dir" value="${env.ANDROID_HOME}">
    <isset property="env.ANDROID_HOME" />
</condition>

<loadproperties srcFile="project.properties" />

<!-- quick check on sdk.dir -->
<fail message="sdk.dir is missing. Make sure ANDROID_HOME 
environment variable is correctly set."
        unless="sdk.dir"/>

<import file="custom_rules.xml" optional="true" />

<!-- version-tag: 1 -->
<import file="${sdk.dir}/tools/ant/build.xml" />

<target name="-pre-compile">
  <path id="project.all.jars.path">
    <path path="${toString:project.all.jars.path}"/>
    <fileset dir="${jar.libs.dir}">
      <include name="*.jar"/>
    </fileset>
  </path>
</target>
</project>

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

<target name="clean">
    <delete dir="Package"/>
    <delete dir="gen"/>
    <delete dir="libs"/>
</target>

<xmlproperty file="AndroidManifest.xml" prefix="custom" 
collapseAttributes="true" />
<condition property="version.code" value="${env.BUILD_NUMBER}" 
else="${custom.manifest.android:versionCode}">
    <isset property="env.BUILD_NUMBER" />
</condition>
<property name="version.name" 
value="${custom.manifest.android:versionName}.${version.code}" />

 <target name="-set-mode-check" depends="android_rules.-set-mode- 
   check, -release-prompt-for-password, -set-apk-filenames" />

 <target name="-set-apk-filenames">
    <condition property="custom.tag" value="release">
        <contains string="${ant.project.invoked-targets}" 
substring="release" />
    </condition>
    <condition property="custom.tag" value="debug">
        <contains string="${ant.project.invoked-targets}" 
substring="debug" />
    </condition>
    <condition property="custom.tag" value="instrumented">
        <contains string="${ant.project.invoked-targets}" 
substring="instrument" />
    </condition>
    <condition property="custom.suffix" value="unsigned" 
else="unaligned">
        <contains string="${ant.project.invoked-targets}" 
    substring="release" />
    </condition>
    </target>
</project>

Must be a way to do it, Visual Studio uses Ant for packaging with .so & .a files for ARM64 but they have some recipe intermediary step that just saves paths to all lib resources.

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文