Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

It seems that the aar/classes.jar should NOT include the R class #235

Merged
merged 1 commit into from
Sep 27, 2013
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,15 @@ public class AarMojo extends AbstractAndroidMojo
* NOTE: This is inconsistent with APK where the folder is called "lib"
*/
public static final String NATIVE_LIBRARIES_FOLDER = "libs";

/**
* Build folder to place built native libraries into
*
* @parameter expression="${android.ndk.build.ndk-output-directory}"
* default-value="${project.build.directory}/ndk-libs"
*/
private File ndkOutputDirectory;

/**
* <p>Classifier to add to the artifact generated. If given, the artifact will be an attachment instead.</p>
*
Expand Down Expand Up @@ -95,11 +95,26 @@ public class AarMojo extends AbstractAndroidMojo
*/
@PullParameter
private String ndkClassifier;

private List<String> sourceFolders = new ArrayList<String>();

/**
* Specifies the files that should be included in the classes.jar within the aar
*
* @parameter
*/
@PullParameter
private String[] classesJarIncludes = new String[]{"**/*"};

/**
* Specifies the files that should be excluded from the classes.jar within the aar
*
* @parameter
*/
@PullParameter
private String[] classesJarExcludes = new String[]{"**/R.class", "**/R$*.class", "**/BuildConfig.class"};

private List<String> sourceFolders = new ArrayList<String>();

/**
* @throws MojoExecutionException
* @throws MojoFailureException
*/
Expand All @@ -108,18 +123,18 @@ public void execute() throws MojoExecutionException, MojoFailureException
String out = project.getBuild().getDirectory();
for ( String src : project.getCompileSourceRoots() )
{
if ( !src.startsWith( out ) )
if ( !src.startsWith( out ) )
{
sourceFolders.add( src );
}
}

generateIntermediateApk();

CommandExecutor executor = CommandExecutor.Factory.createDefaultCommmandExecutor();
executor.setLogger( this.getLog() );

File outputFile = createApkLibraryFile();
File outputFile = createApkLibraryFile( createAarClassesJar() );

if ( classifier == null )
{
Expand All @@ -134,11 +149,40 @@ public void execute() throws MojoExecutionException, MojoFailureException
}

/**
* Creates an appropriate aar/classes.jar that does not include R
*
* @return
* @throws MojoExecutionException
*/
protected File createApkLibraryFile() throws MojoExecutionException
protected File createAarClassesJar() throws MojoExecutionException
{
final File classesJar = new File( project.getBuild().getDirectory(),
project.getBuild().getFinalName() + ".aar.classes.jar" );
try
{
JarArchiver jarArchiver = new JarArchiver();
jarArchiver.setDestFile( classesJar );
jarArchiver.addDirectory( new File( project.getBuild().getOutputDirectory() ),
classesJarIncludes,
classesJarExcludes );
jarArchiver.createArchive();
return classesJar;
}
catch ( ArchiverException e )
{
throw new MojoExecutionException( "ArchiverException while creating ." + classesJar + " file.", e );
}
catch ( IOException e )
{
throw new MojoExecutionException( "IOException while creating ." + classesJar + " file.", e );
}
}

/**
* @return
* @throws MojoExecutionException
*/
protected File createApkLibraryFile( File classesJar ) throws MojoExecutionException
{
final File apklibrary = new File( project.getBuild().getDirectory(),
project.getBuild().getFinalName() + "." + AAR );
Expand All @@ -152,11 +196,8 @@ protected File createApkLibraryFile() throws MojoExecutionException
jarArchiver.addFile( androidManifestFile, "AndroidManifest.xml" );
addDirectory( jarArchiver, assetsDirectory, "assets" );
addDirectory( jarArchiver, resourceDirectory, "res" );

File jarFile = new File( project.getBuild().getDirectory()
+ File.separator + project.getBuild().getFinalName() + ".jar" );
jarArchiver.addFile( jarFile, "classes.jar" );

jarArchiver.addFile( classesJar, "classes.jar" );

File[] overlayDirectories = getResourceOverlayDirectories();
for ( File resOverlayDir : overlayDirectories )
{
Expand Down Expand Up @@ -205,7 +246,7 @@ private void addNativeLibraries( final JarArchiver jarArchiver ) throws MojoExec
}
else
{
getLog().info( nativeLibrariesDirectory
getLog().info( nativeLibrariesDirectory
+ " does not exist, looking for libraries in target directory." );
// Add native libraries built and attached in this build
String[] ndkArchitectures = NativeHelper.getNdkArchitectures( ndkArchitecture,
Expand All @@ -215,7 +256,7 @@ private void addNativeLibraries( final JarArchiver jarArchiver ) throws MojoExec
{
final File ndkLibsDirectory = new File( ndkOutputDirectory, ndkArchitecture );
addSharedLibraries( jarArchiver, ndkLibsDirectory, ndkArchitecture );

// Add native library dependencies
// FIXME: Remove as causes duplicate libraries when building final APK if this set includes
// libraries from dependencies of the AAR
Expand Down Expand Up @@ -324,10 +365,10 @@ protected void addDirectory( JarArchiver jarArchiver, File directory, String pre
getLog().debug( "Added files from " + directory );
}
}

/**
* Adds all shared libraries (.so) to a {@link JarArchiver} under 'libs'.
*
*
* @param jarArchiver The jarArchiver to add files to
* @param directory The directory to scan for .so files
* @param ndkArchitecture The prefix for where in the jar the .so files will go.
Expand Down