Search code examples
protocol-buffersj2objcj2objc-gradle

j2obj translate of javanano protobuf fails to compile


I'm relatively new to Android and j2objc, hoping this issue has a simple fix. I created a simple project to test protobuf nano in Android and translate to objective c. The app runs fine in Java sending messages to a C# web service but the compilation of translated javanano classes in objective c fails with the following error:

j2objc-0.9.8.2.1/include/J2ObjC_header.h:25:17: error: cannot create __weak reference in file using manual reference counting
id JreStrAppend(__weak id *lhs, const char *types, ...);

Here's the build.gradle file:

plugins {
    id 'java'
    id "com.github.j2objccontrib.j2objcgradle" version "0.6.0-alpha"
    id "com.google.protobuf" version "0.7.5"
}

sourceSets {
    main.java.srcDirs += 'src/main/javanano'
}

dependencies {
    // Any libraries you depend on, like Guava or JUnit
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.google.guava:guava:19.0'
    compile 'com.google.protobuf.nano:protobuf-javanano:3.0.0-alpha-5'
    testCompile 'junit:junit:4.12'
}

protobuf {
    protoc {
        artifact = "com.google.protobuf:protoc:3.0.0-beta-2"
    }

    generateProtoTasks {
        all().each { task ->
            task.builtins {
                remove java
                javanano {
                    option 'java_multiple_files=true'
                    option 'ignore_services=true'
                }
            }
        }
    }
    generatedFilesBaseDir = "$projectDir/src"
}

// Plugin settings; put these at the bottom of the file.
j2objcConfig {
    // Sets up libraries you depend on
    autoConfigureDeps true
//    testMinExpectedTests 0

    // Omit these two lines if you don't configure your Xcode project with CocoaPods
//    xcodeProjectDir '/Users/gabrielchoza/SoftwareDev/NGCalDev/AuthTouchId'  //  suggested directory name
//    xcodeTargetsIos 'IOS-APP', 'IOS-APPTests'  // replace with your iOS targets

    finalConfigure()          // Must be last call to configuration
}

And here is one of the photo files:

syntax = "proto3";
option csharp_namespace = "messages";
option java_package = "messages";

message Req {
    string client_version = 1;
    string client_practice = 2;
    string instance_id = 3;
}

We are using the latest version of Xcode: Version 7.3 (7D175), and OS X El Capitan Version 10.11.4

Any help will be appreciated.


Solution

  • You'll want to upgrade to J2ObjC's latest version, 1.0.2, as its J2ObjC_header.h no longer uses the __weak attribute. The change to your Gradle configuration for this newer version is described here.