src/main/java/com/simpligility/maven/plugins/android/phase01generatesources/GenerateSourcesMojo.java
private void generateRForApkLibDependency( Artifact apklibArtifact ) throws MojoExecutionException
    {
        final File unpackDir = getUnpackedLibFolder( apklibArtifact );
        getLog().debug( "Generating incomplete R file for apklib: " + apklibArtifact.getGroupId()
                + ":" + apklibArtifact.getArtifactId() );
        final File apklibManifest = new File( unpackDir, "AndroidManifest.xml" );
        final File apklibResDir = new File( unpackDir, "res" );

        List<File> dependenciesResDirectories = new ArrayList<File>();
        final Set<Artifact> apklibDeps = getDependencyResolver()
                .getLibraryDependenciesFor( this.session, this.repositorySystem, apklibArtifact );
        getLog().debug( "apklib=" + apklibArtifact + "  dependencies=" + apklibDeps );
        for ( Artifact dependency : apklibDeps )
        {
            // Add in the resources that are dependencies of the apklib.
            final String extension = dependency.getType();
            final File dependencyResDir = getUnpackedLibResourceFolder( dependency );
            if ( ( extension.equals( APKLIB ) || extension.equals( AAR ) ) && dependencyResDir.exists() )
            {
                dependenciesResDirectories.add( dependencyResDir );
            }
        }

        // Create combinedAssets for this apklib dependency - can't have multiple -A args
        final File apklibCombAssets = new File( getUnpackedLibFolder( apklibArtifact ), "combined-assets" );
        for ( Artifact dependency : apklibDeps )
        {
            // Accumulate assets for dependencies of the apklib (if they exist).
            final String extension = dependency.getType();
            final File dependencyAssetsDir = getUnpackedLibAssetsFolder( dependency );
            if ( ( extension.equals( APKLIB ) || extension.equals( AAR ) ) )
            {
                copyFolder( dependencyAssetsDir, apklibCombAssets );
            }
        }
        // Overlay the apklib dependency assets (if they exist)
        final File apkLibAssetsDir = getUnpackedLibAssetsFolder( apklibArtifact );
        copyFolder( apkLibAssetsDir, apklibCombAssets );

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

        final AaptCommandBuilder commandBuilder = AaptCommandBuilder
                .packageResources( getLog() )
                .makeResourcesNonConstant()
                .makePackageDirectories()
                .setResourceConstantsFolder( genDirectory )
                .generateRIntoPackage( extractPackageNameFromAndroidManifest( apklibManifest ) )
                .setPathToAndroidManifest( apklibManifest )
                .addResourceDirectoryIfExists( apklibResDir )
                .addResourceDirectoriesIfExists( dependenciesResDirectories )
                .autoAddOverlay()
                .addRawAssetsDirectoryIfExists( apklibCombAssets )
                .addExistingPackageToBaseIncludeSet( getAndroidSdk().getAndroidJar() )
                .addConfigurations( configurations )
                .setVerbose( aaptVerbose )
                .addExtraArguments( aaptExtraArgs )
                // We need to generate R.txt for all projects as it needs to be consumed when generating R class.
                // It also needs to be consumed when packaging aar.
                .generateRTextFile( unpackDir );

        getLog().debug( getAndroidSdk().getAaptPath() + " " + commandBuilder.toString() );
        try
        {
            executor.setCaptureStdOut( true );
            final List<String> commands = commandBuilder.build();
            executor.executeCommand( getAndroidSdk().getAaptPath(), commands, project.getBasedir(), false );
        }
        catch ( ExecutionException e )
        {
            throw new MojoExecutionException( "", e );
        }
    }
private void generateRForApkLibDependency( Artifact apklibArtifact ) throws MojoExecutionException
    {
        final File unpackDir = getUnpackedLibFolder( apklibArtifact );
        getLog().debug( "Generating incomplete R file for apklib: " + apklibArtifact.getGroupId()
                + ":" + apklibArtifact.getArtifactId() );
        final File apklibManifest = new File( unpackDir, "AndroidManifest.xml" );
        final File apklibResDir = new File( unpackDir, "res" );

        List<File> dependenciesResDirectories = new ArrayList<File>();
        final Set<Artifact> apklibDeps = getDependencyResolver()
                .getLibraryDependenciesFor( this.session, this.repositorySystem, apklibArtifact );
        getLog().debug( "apklib=" + apklibArtifact + "  dependencies=" + apklibDeps );
        for ( Artifact dependency : apklibDeps )
        {
            // Add in the resources that are dependencies of the apklib.
            final String extension = dependency.getType();
            final File dependencyResDir = getUnpackedLibResourceFolder( dependency );
            if ( ( extension.equals( APKLIB ) || extension.equals( AAR ) ) && dependencyResDir.exists() )
            {
                dependenciesResDirectories.add( dependencyResDir );
            }
        }

        // Create combinedAssets for this apklib dependency - can't have multiple -A args
        final File apklibCombAssets = new File( getUnpackedLibFolder( apklibArtifact ), "combined-assets" );
        for ( Artifact dependency : apklibDeps )
        {
            // Accumulate assets for dependencies of the apklib (if they exist).
            final String extension = dependency.getType();
            final File dependencyAssetsDir = getUnpackedLibAssetsFolder( dependency );
            if ( ( extension.equals( APKLIB ) || extension.equals( AAR ) ) )
            {
                copyFolder( dependencyAssetsDir, apklibCombAssets );
            }
        }
        // Overlay the apklib dependency assets (if they exist)
        final File apkLibAssetsDir = getUnpackedLibAssetsFolder( apklibArtifact );
        copyFolder( apkLibAssetsDir, apklibCombAssets );

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

        final AaptCommandBuilder commandBuilder = AaptCommandBuilder
                .packageResources( getLog() )
                .makeResourcesNonConstant()
                .makePackageDirectories()
                .setResourceConstantsFolder( genDirectory )
                .generateRIntoPackage( extractPackageNameFromAndroidManifest( apklibManifest ) )
                .setPathToAndroidManifest( apklibManifest )
                .addResourceDirectoryIfExists( apklibResDir )
                .addResourceDirectoriesIfExists( dependenciesResDirectories )
                .autoAddOverlay()
                .addRawAssetsDirectoryIfExists( apklibCombAssets )
                .addExistingPackageToBaseIncludeSet( getAndroidSdk().getAndroidJar() )
                .addConfigurations( configurations )
                .setVerbose( aaptVerbose )
                .addExtraArguments( aaptExtraArgs )
                // We need to generate R.txt for all projects as it needs to be consumed when generating R class.
                // It also needs to be consumed when packaging aar.
                .generateRTextFile( unpackDir );

        getLog().debug( getAndroidSdk().getAaptPath() + " " + commandBuilder.toString() );
        try
        {
            executor.setCaptureStdOut( true );
            final List<String> commands = commandBuilder.build();
            executor.executeCommand( getAndroidSdk().getAaptPath(), commands, project.getBasedir(), false );
        }
        catch ( ExecutionException e )
        {
            throw new MojoExecutionException( "", e );
        }
    }
private void generateRForApkLibDependency ( Artifact apklibArtifact ) throws MojoExecutionException { final File unpackDir = getUnpackedLibFolder ( apklibArtifact ) ; getLog ( ) . debug ( "Generating incomplete R file for apklib: " + apklibArtifact . getGroupId ( ) + ":" + apklibArtifact . getArtifactId ( ) ) ; final File apklibManifest = new File ( unpackDir , "AndroidManifest.xml" ) ; final File apklibResDir = new File ( unpackDir , "res" ) ; List < File > dependenciesResDirectories = new ArrayList < File > ( ) ; final Set < Artifact > apklibDeps = getDependencyResolver ( ) . getLibraryDependenciesFor ( this . session , this . repositorySystem , apklibArtifact ) ; getLog ( ) . debug ( "apklib=" + apklibArtifact + "  dependencies=" + apklibDeps ) ; for ( Artifact dependency : apklibDeps ) { // Add in the resources that are dependencies of the apklib. final String extension = dependency . getType ( ) ; final File dependencyResDir = getUnpackedLibResourceFolder ( dependency ) ; if ( ( extension . equals ( APKLIB ) || extension . equals ( AAR ) ) && dependencyResDir . exists ( ) ) { dependenciesResDirectories . add ( dependencyResDir ) ; } } // Create combinedAssets for this apklib dependency - can't have multiple -A args final File apklibCombAssets = new File ( getUnpackedLibFolder ( apklibArtifact ) , "combined-assets" ) ; for ( Artifact dependency : apklibDeps ) { // Accumulate assets for dependencies of the apklib (if they exist). final String extension = dependency . getType ( ) ; final File dependencyAssetsDir = getUnpackedLibAssetsFolder ( dependency ) ; if ( ( extension . equals ( APKLIB ) || extension . equals ( AAR ) ) ) { copyFolder ( dependencyAssetsDir , apklibCombAssets ) ; } } // Overlay the apklib dependency assets (if they exist) final File apkLibAssetsDir = getUnpackedLibAssetsFolder ( apklibArtifact ) ; copyFolder ( apkLibAssetsDir , apklibCombAssets ) ; final CommandExecutor executor = CommandExecutor . Factory . createDefaultCommmandExecutor ( ) ; executor . setLogger ( getLog ( ) ) ; final AaptCommandBuilder commandBuilder = AaptCommandBuilder . packageResources ( getLog ( ) ) . makeResourcesNonConstant ( ) . makePackageDirectories ( ) . setResourceConstantsFolder ( genDirectory ) . generateRIntoPackage ( extractPackageNameFromAndroidManifest ( apklibManifest ) ) . setPathToAndroidManifest ( apklibManifest ) . addResourceDirectoryIfExists ( apklibResDir ) . addResourceDirectoriesIfExists ( dependenciesResDirectories ) . autoAddOverlay ( ) . addRawAssetsDirectoryIfExists ( apklibCombAssets ) . addExistingPackageToBaseIncludeSet ( getAndroidSdk ( ) . getAndroidJar ( ) ) . addConfigurations ( configurations ) . setVerbose ( aaptVerbose ) . addExtraArguments ( aaptExtraArgs ) // We need to generate R.txt for all projects as it needs to be consumed when generating R class. // It also needs to be consumed when packaging aar. . generateRTextFile ( unpackDir ) ; getLog ( ) . debug ( getAndroidSdk ( ) . getAaptPath ( ) + " " + commandBuilder . toString ( ) ) ; try { executor . setCaptureStdOut ( true ) ; final List < String > commands = commandBuilder . build ( ) ; executor . executeCommand ( getAndroidSdk ( ) . getAaptPath ( ) , commands , project . getBasedir ( ) , false ) ; } catch ( ExecutionException e ) { throw new MojoExecutionException ( "" , e ) ; } }
Executes aapt to generate the R class for the given apklib.

@param apklibArtifact apklib for which to generate the R class.
@throws MojoExecutionException if it fails.
Executes aapt to generate the R class for the given apklib .