The correct way to handle ant builds for the Android library. String excludes R.class from jar file

A problem is currently running when our production build using ant excludes the R.class file. Looking at the ADT build.xml, I see the following:

<if condition="${project.is.library}">
<then>
...
    <jar destfile="${out.library.jar.file}">
        <fileset dir="${out.classes.absolute.dir}"
            includes="**/*.class"
            excludes="${project.app.package.path}/R.class ${project.app.package.path}/R$*.class ${project.app.package.path}/BuildConfig.class"/>
        <fileset dir="${source.absolute.dir}"
            excludes="**/*.java ${android.package.excludes}" />
</jar>
</then>
</if>

Currently, the assembly grabs the classes.jar file, but as you can see above, this does not include the R.class file, so when the library tries to grab the external line, it explodes on NoClassDefFoundError

Update: The following quote was given here: http://tools.android.com/recent/dealingwithdependenciesinandroidprojects

Important change:

We have changed the way library projects and class packages are generated:

  • Class R is not yet packaged in the library library project output file.
  • R , . R .

, R- , . , R . , R , , , R .

, , Android?

2: , R.class R $*. jar.

, "" Android, ADT . "" , .

+4
2

.

  • R , R .

  • ant sript, SDK Android, R .

  • , Java. .

  • R . Resources . :

    setContentView(getResources().getIdentifier("your_layout_id", "layout", getPackageName()));
    // is equals to setContentView(R.layout.your_layout_id);
    
+1

,

<src path="../src"/>
<src path="../gen"/>

to <javac>:

: fooobar.com/questions/1514147/...

0

All Articles