Skip to content
This repository has been archived by the owner on Apr 2, 2024. It is now read-only.

Commit

Permalink
Merge pull request simpligility#233 from johanlindquist/master
Browse files Browse the repository at this point in the history
Multiple native architecture support
  • Loading branch information
mosabua committed Sep 18, 2013
2 parents 7c7f21a + d4ece8d commit 1f4dffa
Show file tree
Hide file tree
Showing 10 changed files with 452 additions and 110 deletions.
53 changes: 50 additions & 3 deletions src/main/java/com/jayway/maven/plugins/android/AndroidNdk.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
*/
package com.jayway.maven.plugins.android;

import com.jayway.maven.plugins.android.configuration.NDKArchitectureToolchainMappings;
import com.jayway.maven.plugins.android.phase05compile.NdkBuildMojo;
import org.apache.commons.lang.SystemUtils;
import org.apache.maven.plugin.MojoExecutionException;
Expand Down Expand Up @@ -40,18 +41,18 @@ public class AndroidNdk
/**
* Arm toolchain implementations.
*/
private static final String[] ARM_TOOLCHAIN = { "arm-linux-androideabi-4.7", "arm-linux-androideabi-4.6",
public static final String[] ARM_TOOLCHAIN = { "arm-linux-androideabi-4.7", "arm-linux-androideabi-4.6",
"arm-linux-androideabi-4.4.3" };

/**
* x86 toolchain implementations.
*/
private static final String[] X86_TOOLCHAIN = { "x86-4.7", "x86-4.6", "x86-4.4.3" };
public static final String[] X86_TOOLCHAIN = { "x86-4.7", "x86-4.6", "x86-4.4.3" };

/**
* Mips toolchain implementations.
*/
private static final String[] MIPS_TOOLCHAIN = { "mipsel-linux-android-4.7", "mipsel-linux-android-4.6",
public static final String[] MIPS_TOOLCHAIN = { "mipsel-linux-android-4.7", "mipsel-linux-android-4.6",
"mipsel-linux-android-4.4.3" };

/**
Expand Down Expand Up @@ -251,4 +252,50 @@ else if ( ndkArchitecture.startsWith( "mips" ) )
throw new MojoExecutionException( "gdbserver binary for architecture " + ndkArchitecture
+ " does not exist, please double check the toolchain and OS used" );
}

/** Retrieves, based on the architecture and possibly toolchain mappings, the toolchain for the architecture.
* <br/>
* <strong>Note:</strong> This method will return the <strong>default</strong> toolchain as defined by the NDK if
* not specified in the <code>NDKArchitectureToolchainMappings</code>.
*
* @param ndkArchitecture Architecture to resolve toolchain for
* @param ndkArchitectureToolchainMappings User mappings of architecture to toolchain
*
* @return Toolchain to be used for the architecture
*
* @throws MojoExecutionException If a toolchain can not be resolved
*/
public String getToolchainFromArchitecture( final String ndkArchitecture,
final NDKArchitectureToolchainMappings ndkArchitectureToolchainMappings
) throws MojoExecutionException
{
if ( ndkArchitecture.startsWith( "arm" ) )
{
if ( ndkArchitectureToolchainMappings != null )
{
return ndkArchitectureToolchainMappings.getArmeabi();
}
return AndroidNdk.ARM_TOOLCHAIN[1];
}
else if ( ndkArchitecture.startsWith( "x86" ) )
{
if ( ndkArchitectureToolchainMappings != null )
{
return ndkArchitectureToolchainMappings.getX86();
}
return AndroidNdk.X86_TOOLCHAIN[1];
}
else if ( ndkArchitecture.startsWith( "mips" ) )
{
if ( ndkArchitectureToolchainMappings != null )
{
return ndkArchitectureToolchainMappings.getMips();
}
return AndroidNdk.MIPS_TOOLCHAIN[1];
}

// if we got here, throw an error
throw new MojoExecutionException( "Toolchain for architecture " + ndkArchitecture
+ "does not exist, please double check the setup" );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -370,20 +370,68 @@ public static String[] getAppAbi( File applicationMakefile )
return null;
}

public static String[] getNdkArchitectures( final String ndkClassifier, final String ndkArchitecture,
final String applicationMakefile, final File basedir )
throws MojoExecutionException

/** Extracts, if embedded correctly, the artifacts architecture from its classifier. The format of the
* classifier, if including the architecture is &lt;architecture&gt;-&lt;classifier&gt;. If no
* architecture is embedded in the classifier, 'armeabi' will be returned.
*
*
* @param artifact The artifact to retrieve the classifier from.
* @param defaultArchitecture The architecture to return if can't be resolved from the classifier
* @return The retrieved architecture, or <code>defaulArchitecture</code> if not resolveable
*/
public static String extractArchitectureFromArtifact( Artifact artifact, final String defaultArchitecture )
{
// if there is a classifier, return it
if ( ndkClassifier != null )
String classifier = artifact.getClassifier();
if ( classifier != null )
{
return new String[] { ndkClassifier };
//
// We loop backwards to catch the case where the classifier is
// potentially armeabi-v7a - this collides with armeabi if looping
// through this loop in the other direction
//

for ( int i = AndroidNdk.NDK_ARCHITECTURES.length - 1; i >= 0; i-- )
{
String ndkArchitecture = AndroidNdk.NDK_ARCHITECTURES[i];
if ( classifier.startsWith( ndkArchitecture ) )
{
return ndkArchitecture;
}
}

}
// Default case is to return the default architecture
return defaultArchitecture;
}

/** Attempts to extract, from various sources, the applicable list of NDK architectures to support
* as part of the build.
* <br/>
* <br/>
* It retrieves the list from the following places:
* <ul>
* <li>ndkArchitecture parameter</li>
* <li>projects Application.mk - currently only a single architecture is supported by this method</li>
* </ul>
*
*
* @param ndkArchitectures Space separated list of architectures. This may be from configuration or otherwise
* @param applicationMakefile The makefile (Application.mk) to retrieve the list from.
* @param basedir Directory the build is running from (to resolve files)
*
* @return List of architectures to be supported by build.
*
* @throws MojoExecutionException
*/
public static String[] getNdkArchitectures( final String ndkArchitectures, final String applicationMakefile,
final File basedir )
throws MojoExecutionException
{
// if there is a specified ndk architecture, return it
if ( ndkArchitecture != null )
if ( ndkArchitectures != null )
{
return new String[] { ndkArchitecture };
return ndkArchitectures.split( " " );
}

// if there is no application makefile specified, let's use the default one
Expand All @@ -407,4 +455,22 @@ public static String[] getNdkArchitectures( final String ndkClassifier, final St
// return a default ndk architecture
return new String[] { "armeabi" };
}

/** Helper method for determining whether the specified architecture is a match for the
* artifact using its classifier. When used for architecture matching, the classifier must be
* formed by &lt;architecture&gt;-&lt;classifier&gt;.
* If the artifact is legacy and defines no valid architecture, the artifact architecture will
* default to <strong>armeabi</strong>.
*
* @param ndkArchitecture Architecture to check for match
* @param artifact Artifact to check the classifier match for
* @return True if the architecture matches, otherwise false
*/
public static boolean artifactHasHardwareArchitecture( Artifact artifact, String ndkArchitecture,
String defaultArchitecture )
{
return "so".equals( artifact.getType() )
&& ndkArchitecture.equals( extractArchitectureFromArtifact( artifact, defaultArchitecture ) );
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package com.jayway.maven.plugins.android.configuration;

import com.jayway.maven.plugins.android.AndroidNdk;

/**
* @author
*/
public class NDKArchitectureToolchainMappings
{
String x86 = AndroidNdk.X86_TOOLCHAIN[1];
String armeabi = AndroidNdk.ARM_TOOLCHAIN[1];
String mips = AndroidNdk.ARM_TOOLCHAIN[1];

public String getArmeabi()
{
return armeabi;
}

public void setArmeabi( final String armeabi )
{
this.armeabi = armeabi;
}

public String getMips()
{
return mips;
}

public void setMips( final String mips )
{
this.mips = mips;
}

public String getX86()
{
return x86;
}

public void setX86( final String x86 )
{
this.x86 = x86;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public static void cleanupAfterBuild( MakefileHolder makefileHolder )
* @return The created Makefile
*/
public MakefileHolder createMakefileFromArtifacts( File outputDir, Set<Artifact> artifacts,
String ndkArchitecture,
String ndkArchitecture, String defaultNDKArchitecture,
boolean useHeaderArchives )
throws IOException, MojoExecutionException
{
Expand All @@ -157,13 +157,11 @@ public MakefileHolder createMakefileFromArtifacts( File outputDir, Set<Artifact>
{
for ( Artifact artifact : artifacts )
{
boolean apklibStatic = false;
final String architecture = NativeHelper.extractArchitectureFromArtifact( artifact,
defaultNDKArchitecture );

if ( artifact.hasClassifier() )
{
makeFile.append( '\n' );
makeFile.append( "ifeq ($(TARGET_ARCH_ABI)," ).append( artifact.getClassifier() ).append( ")\n" );
}
makeFile.append( '\n' );
makeFile.append( "ifeq ($(TARGET_ARCH_ABI)," ).append( architecture ).append( ")\n" );

makeFile.append( "#\n" );
makeFile.append( "# Group ID: " );
Expand All @@ -183,7 +181,9 @@ public MakefileHolder createMakefileFromArtifacts( File outputDir, Set<Artifact>
makeFile.append( "LOCAL_MODULE := " );
makeFile.append( artifact.getArtifactId() );
makeFile.append( '\n' );
apklibStatic = addLibraryDetails( makeFile, outputDir, artifact, ndkArchitecture );

final boolean apklibStatic = addLibraryDetails( makeFile, outputDir, artifact, ndkArchitecture );

if ( useHeaderArchives )
{
try
Expand Down Expand Up @@ -237,11 +237,9 @@ public boolean include( JarEntry jarEntry )
makeFile.append( "include $(PREBUILT_SHARED_LIBRARY)\n" );
}

if ( artifact.hasClassifier() )
{
makeFile.append( "endif #" ).append( artifact.getClassifier() ).append( '\n' );
makeFile.append( '\n' );
}
makeFile.append( "endif #" ).append( artifact.getClassifier() ).append( '\n' );
makeFile.append( '\n' );

}
}

Expand Down
Loading

0 comments on commit 1f4dffa

Please sign in to comment.