Problem building native code samples with 2.3, reports 'Invalid NativePlatform: linux_i686'

After upgrading to Gradle 2.3 I can’t build anything native related, even the Gradle samples from the 2.3 distribution.

Every attempt in a directory with a script using native plugin ends with the following error:

FAILURE: Build failed with an exception.

  • What went wrong: A problem occurred configuring root project ‘c’. > Exception thrown while executing model rule: org.gradle.nativeplatform.plugins.NativeComponentModelPlugin$Rules#createNativeBinaries(org.gradle.platform.base.BinaryContainer, org.gradle.api.NamedDomainObjectSet<org.gradle.nativeplatform.NativeComponentSpec>, org.gradle.language.base.internal.LanguageRegistry, org.gradle.nativeplatform.toolchain.internal.NativeToolChainRegistryInternal, org.gradle.platform.base.internal.PlatformResolver, org.gradle.nativeplatform.BuildTypeContainer, org.gradle.nativeplatform.FlavorContainer, org.gradle.internal.service.ServiceRegistry, java.io.File)

Invalid NativePlatform: linux_i686

Executing Gradle -v shows the following information from my environment:

------------------------------------------------------------ Gradle 2.3 ------------------------------------------------------------

Build time:

2015-02-16 05:09:33 UTC Build number: none Revision:

586be72bf6e3df1ee7676d1f2a3afd9157341274

Groovy:

2.3.9 Ant:

Apache Ant™ version 1.9.3 compiled on December 23 2013 JVM:

1.8.0_40-internal (Oracle Corporation 25.40-b13) OS:

Linux 3.16.0-12-generic i386

What error are you getting when building the C sample?

Can you post your build script?

The error posted was the one received when trying to build the C sample.

I have not made any changes to samples build scripts, so here you have the build script used for this test as included in samples directory:

apply plugin: ‘c’

model {

components {

hello(NativeLibrarySpec)

}

}

model {

components {

main(NativeExecutableSpec) {

sources {

c.lib library: “hello”

}

}

}

}

binaries.all {

// Define toolchain-specific compiler and linker options

if (toolChain in Gcc) {

cCompiler.args “-O2”

linker.args “-Xlinker”, “-S”

}

if (toolChain in VisualCpp) {

cCompiler.args “/Zi”

linker.args “/DEBUG”

}

}

// For any shared library binaries built with Visual C++,

// define the DLL_EXPORT macro

binaries.withType(SharedLibraryBinarySpec) {

if (toolChain in VisualCpp) {

cCompiler.args “/Zi”

cCompiler.define “DLL_EXPORT”

}

}

Thanks. Can you tell me about your environment? e.g., uname -a, OS, etc?

Can you try running printArch from this build script?

buildscript {
     repositories {
         jcenter()
    }
    dependencies {
         classpath 'net.rubygrapefruit:native-platform:0.10'
    }
}
  import org.gradle.nativeplatform.platform.internal.DefaultNativePlatform
import net.rubygrapefruit.platform.Native
import net.rubygrapefruit.platform.SystemInfo
  task printArch() {
    doLast {
        try {
             println "From native path: " + Native.get(SystemInfo.class).getArchitectureName()
        } catch (Exception e) {
            println "Couldn't get arch ${e.message}"
        }
        println "System property: " + System.getProperty("os.arch")
        println "Current arch: " + DefaultNativePlatform.getCurrentArchitecture()
    }
}

Here is the requested information:

uname -a

Linux ubuntu.lenovoX61t 3.16.0-12-generic #18-Ubuntu SMP Mon Sep 1 13:04:08 UTC 2014 i686 i686 i686 GNU/Linux

gradle printArch

:printArch

From native path: i686

System property: i386

Current arch: architecture ‘i686’

My operating system is LUbuntu running on a Virtual Machine (VirtualBox). I’ve changed permissions in the gradle folder to be the owner of the files but with no effect.

Thanks a lot for your help.

Ah, thanks. We’re currently not aliasing i686 to i386 like we should. This may have worked before because we were pretty lax with how we matched up platforms.

Could you try adding this to the C sample?

model {
    platforms {
        linux_i686 {
            operatingSystem "linux"
            architecture "i386"
        }
    }
}

I made GRADLE-3246 I think we can treat i686 like we treat the other i386-aliases

It works perfect now.

Thanks again for your help.