Search code examples
androidj2objcj2objc-gradle

J2Ojbc native compile- guava headers missing


We are porting an iOS application to Android and are exploring J2objc and protobuf. So far we are working through the issues (we're new to Android and a number of them are due to learning curve).

This particular issue seems like a bug on the latest version of j2objc-1.0-2.2. The #includes in the translated objective c implementation classes are not being changed to camel case. Has anyone seen this behavior? Is this a bug or some setting we're missing?

Thanks for your help.

Here is the compilation error:

GcatMobile/shared/build/j2objcSrcGenMain/com/gcatconsult/shared/remote/NetworkBase.m:14:10: fatal error:
'com/google/common/io/BaseEncoding.h' file not found

#include "com/google/common/io/BaseEncoding.h"

Here are the #includes in NetworkBase.m, my translated implementation class:

#include "IOSClass.h"
#include "IOSPrimitiveArray.h"
#include "J2ObjC_source.h"
#include "com/gcatconsult/shared/messages/nano/Resp.h"
#include "com/gcatconsult/shared/remote/NetworkBase.h"
#include "com/google/common/io/BaseEncoding.h"
#include "com/google/protobuf/nano/MessageNano.h"
#include "java/io/BufferedInputStream.h"
#include "java/io/ByteArrayOutputStream.h"
#include "java/io/InputStream.h"
#include "java/io/OutputStream.h"
#include "java/io/PrintStream.h"
#include "java/lang/Exception.h"
#include "java/lang/Integer.h"
#include "java/lang/System.h"
#include "java/net/HttpURLConnection.h"
#include "java/net/MalformedURLException.h"
#include "java/net/URL.h"
#include "java/net/URLConnection.h"
#include "java/util/zip/GZIPOutputStream.h"

Here is 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
    skipJ2objcVerification true
    translateClasspaths = ["../../SoftwareDev/NgCalDev/External/j2objc-1.0-2.2/lib/guava-19.0.jar"]
    translateArgs '--prefixes', 'src/main/resources/prefixes.properties'
//    testMinExpectedTests 0

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

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

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


Solution

  • Guava is in the process of upgrading its API to Java 8, and so developers need a way to include different versions of it. The Guava includes were therefore moved to /include/guava/, so you need to add that path to your Header Search Paths.