I configured my android project to use ant. When building using the keyword release it fails with this message:
java.lang.NullPointerException
at com.android.ant.ApkBuilderTask.execute(ApkBuilderTask.java:239)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
It fails on build.xml line 249 which is included here:
<macrodef name="package-helper">
<attribute name="sign.package" />
<element name="extra-jars" optional="yes" />
<sequential>
<apkbuilder
outfolder="${out.absolute.dir}"
basename="${ant.project.name}"
signed="@{sign.package}"
debug="${manifest.debuggable}"
verbose="${verbose}"> **LINE 249 IS HERE**
<file path="${intermediate.dex.file}" />
<sourcefolder path="${source.absolute.dir}" />
<sourcefolder refid="android.libraries.src" />
<jarfolder path="${external.libs.absolute.dir}" />
<jarfolder refid="android.libraries.libs" />开发者_如何学Go
<nativefolder path="${native.libs.absolute.dir}" />
<nativefolder refid="android.libraries.libs" />
<extra-jars/>
</apkbuilder>
</sequential>
</macrodef>
That is called from line 401 which contains these lines:
<target name="-package-release" depends="-dex, -package-resources">
<package-helper sign.package="false" />
</target>
It looks like there is some problem with ApkBuilderTask.java but I don't know how/where to get the source of ApkBuilderTask.java. Has anyone run into this problem and found a solution? I'm using android SDK tools revision 7 if that helps.
Note: Running "ant debug" or "ant release" all comes out to the same result.
This is a change introduced in the r7 tools. You need to update the <apkbuilder>
task in your build.xml
, in the ways that saturnine points out above.
Given that this error only happens when you customize your build.xml, I think you need to go back and redo the customizations. If you look for $ANDROID_SDK/tools/ant/ant_rules_r3.xml
and paste them into your build.xml
(replacing the definitions that you pasted in last time), it should fix your problems.
You may be able to get away without customizations, as the new version of the rules are far more customizable, and include -pre-compile
and -post-compile
hooks.
Here is the source code for the ant task:
https://android.googlesource.com/platform/sdk/+/tools_r7/anttasks/src/com/android/ant
Looks like the variable mDexPath is null, and I don't see a <dex>
element inside the <apkbuilder>
. Did you see this warning anywhere: "WARNING: Using deprecated <file> inner element in ApkBuilderTask."
?
Did you create your own ant script to or are you using a project created by the android tool? You might want to copy your source code, resources, AndroidManifest.xml and other libraries/assets into a newly created Android project to fix it.
Another reason for this w/ the r8 SDK is that your apkbuilder call is missing the
resourcefile="${resource.package.file.name}"
attribute.
If your error is at
com.android.ant.ApkBuilderTask.execute(ApkBuilderTask.java:257)
, add that to your apkbuilder task call.
精彩评论