Ant compiled jar file, ANE does not recognize

Source: Internet
Author: User
Tags echo message

Ant compiled jar file, ANE does not recognize

Problem description

The Android ANE package requires a jar file. Eclipse can provide export of jar files.

However, there was a problem with the jar file when I used ant to automate the ANE packaging process.

If you use an ant-generated jar file to package the ANE. Then when the ANE is in use, an ExtensionContext uninitialized condition occurs.

That is, at the time of invocation ExtensionContext.createExtensionContext(EXTENSION_ID) , the resulting is always null.

Problem analysis

The following is the target for the build jar:

<target name= "Android" description= "Build android Library" > <delete dir= ". /android/temp "/> <mkdir dir=". /android/temp/classes "/> <echo message=" Using Java version ${ant.java.version}. " /> <javac source= "1.6" srcdir= ". /android/src "Destdir=". /android/temp/classes "Includeantruntime=" false "> <classpath> <pathelement location=" ${andro            Id.sdk}/android.jar "/> <pathelement location=" ${flex.sdk}/lib/android/flashruntimeextensions.jar "/> <pathelement location= ". /android/libs/android-support-v4.jar "/> <pathelement location=" ${android.tools}/support/annotations.jar "/ > </classpath> </javac> <mkdir dir= ". /temp/android/"/> <jar basedir=". /android/temp/classes "destfile=". /temp/android/lib${name}.jar "/> <copy todir=". /temp/android/res/"> <fileset dir=". /android/res "/> </copy> <delete dir=". /andRoid/temp "/></target> 

The jar files that are packaged by Ant are smaller than the jar files exported with eclipse. After unpacking the packaged jar file, I found that the class file compiled with Ant is smaller than the Eclipse compilation.

Therefore, should look for the reason from the Javac.

Solution process soy sauce debug

Add a parameter to the JAVAC task first debug="on" . The compiled class file is similar in size to eclipse. But the ane that was made still doesn't work.

JDT compiler

Because the compiler for eclipse is different from the one used by ant by default, I try to replace the Ant compiler with eclipse. The steps for using the JDT compiler are:

    1. Go to Eclipse downloads to find a version, go to download page, search JDT Core Batch Compiler , can download to JDT compiler;
    2. Copy the extracted ecj-<version>.jar to Ant's lib directory;
    3. To add parameters to the Javac task compiler="org.eclipse.jdt.core.JDTCompilerAdapter" , run the task.

Javac reports the following error:

Target level ' 1.2 ' was incompatible with the source level ' 1.6 '. A target level ' 1.6 ' or better is required

To add a parameter to the JAVAC task target="1.6" , run the task normally. The complete Javac parameters are as follows:

.....<javac source="1.6" srcdir="../android/src" destdir="../android/temp/classes" includeantruntime="false" compiler="org.eclipse.jdt.core.JDTCompilerAdapter" target="1.6">.....

Then generate ane for debugging, everything is OK, problem solved.

Javac compiler

Now that the JDT compiler is working correctly, is it normal to use the javac default compiler (the JDK comes with the compiler)?

Delete compiler parameter settings, keep target parameter settings, run task Normally, generate ANE debug, everything is OK.

<target name= "Android" description= "Build android Library" > <delete dir= ". /android/temp "/> <mkdir dir=". /android/temp/classes "/> <echo message=" Using Java version ${ant.java.version}. " /> <javac source= "1.6" target= "1.6" srcdir= "... /android/src "Destdir=". /android/temp/classes "Includeantruntime=" false "> <classpath> <pathelement location=" ${andro            Id.sdk}/android.jar "/> <pathelement location=" ${flex.sdk}/lib/android/flashruntimeextensions.jar "/> <pathelement location= ". /android/libs/android-support-v4.jar "/> <pathelement location=" ${android.tools}/support/annotations.jar "/ > </classpath> </javac> <mkdir dir= ". /temp/android/"/> <jar basedir=". /android/temp/classes "destfile=". /temp/android/lib${name}.jar "/> <copy todir=". /temp/android/res/"> <fileset dir=". /android/res "/> </copy> <deletE dir= ". /android/temp "/></target>
Conclusion

Originally, the real reason why class could not be used is not the compiler difference, but the target version was not set at compile time. In Eclipse compilation settings, the target version is added to the compilation parameters by default, and Ant does not.

My auto-compiled ANE feature has finally been perfected.

Ant compiled jar file, ANE does not recognize

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.