我们正在将 iOS 应用程序移植到 Android 并正在探索 J2objc 和 protobuf。到目前为止,我们正在解决这些问题(我们是 Android 新手,其中一些问题是由于学习曲线造成的)。
这个特殊问题似乎是最新版本的 j2objc-1.0-2.2 上的一个错误。翻译后的目标 c 实现类中的#includes 不会更改为驼峰式。有没有人见过这种行为?这是一个错误还是我们缺少的某些设置?
谢谢你的帮助。
这是编译错误:
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"
这是我翻译的实现类 NetworkBase.m 中的#includes:
#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"
这是 build.gradle 文件:
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
}
我们正在使用 J2objc 1.0-2.2,Xcode 的最新版本:版本 7.3 (7D175) 和 OS X El Capitan 版本 10.11.4