我是OSX的新手。今天我尝试在Android Studio中使用RxJava和Retrolambda, Retrolambda需要gradle——Retrolambda .
所以我开始config:
1。我粘贴了一小段代码到~/。设置JAVA7_HOME和JAVA8_HOME
export JAVA7_HOME=/Library/Java/JavaVirtualMachines/jdk1.7.0_79.jdk/Contents/Home
export PATH=$JAVA_HOME/bin:$PATH
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export JAVA8_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home
export PATH=$JAVA_HOME/bin:$PATH
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
PATH="/Library/Frameworks/Python.framework/Versions/3.4/bin:${PATH}"
export PATH
似乎工作正常,我检查它使用终端
echo $JAVA8_HOME
/Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home
echo $JAVA7_HOME
/Library/Java/JavaVirtualMachines/jdk1.7.0_79.jdk/Contents/Home
然后我关注别人的文章
2。编辑Android Studio ->首选项->路径变量新增"JAVA8_HOME"one_answers"JAVA7_HOME",同上
3。编辑的构建。gradle(项目)
dependencies {
classpath 'com.android.tools.build:gradle:1.3.0'
classpath 'me.tatarka:gradle-retrolambda:3.2.2'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
4。编辑build.gradle (app)
apply plugin: 'com.android.application'
apply plugin: 'me.tatarka.retrolambda' #Added here!
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
defaultConfig {
applicationId "com.example.ezioshiki.demoproject"
minSdkVersion 16
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
#Added here!
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
#Added here!
String java8 = getJavaVersion(8)
String java7 = getJavaVersion(7)
retrolambda {
jdk java8 //have tried with JAVA8_HOME
oldJdk java7 //have tried with JAVA6_HOME
javaVersion JavaVersion.VERSION_1_7 //have matched the above with VERSION_1_6
}
String getJavaVersion(Integer v) {
def sout = new StringBuffer()
def proc = "/usr/libexec/java_home -v 1.$v".execute()
proc.consumeProcessOutput(sout, new StringBuffer())
proc.waitForOrKill(1000)
return sout.toString().replace("n", "").replace("r", "")
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:23.0.1'
compile 'com.jakewharton:butterknife:7.0.1'
compile 'com.android.support:recyclerview-v7:23.0.1'
compile 'io.reactivex:rxjava:1.0.14'
compile 'net.orfjackal.retrolambda:retrolambda:2.0.6'
compile 'me.tatarka:gradle-retrolambda:3.2.2'
}
我遵循https://github.com/evant/gradle-retrolambda/issues/61,因为grad- retrolambda官方建议找不到Java8,这个问题起作用了。
但是它给了我:
Information:Gradle tasks [:app:assembleDebug]
:app:preBuild UP-TO-DATE
:app:preDebugBuild UP-TO-DATE
:app:checkDebugManifest
:app:preReleaseBuild UP-TO-DATE
:app:prepareComAndroidSupportAppcompatV72301Library UP-TO-DATE
:app:prepareComAndroidSupportRecyclerviewV72301Library UP-TO-DATE
:app:prepareComAndroidSupportSupportV42301Library UP-TO-DATE
:app:prepareDebugDependencies
:app:compileDebugAidl UP-TO-DATE
:app:compileDebugRenderscript UP-TO-DATE
:app:generateDebugBuildConfig UP-TO-DATE
:app:generateDebugAssets UP-TO-DATE
:app:mergeDebugAssets UP-TO-DATE
:app:generateDebugResValues UP-TO-DATE
:app:generateDebugResources UP-TO-DATE
:app:mergeDebugResources UP-TO-DATE
:app:processDebugManifest UP-TO-DATE
:app:processDebugResources UP-TO-DATE
:app:generateDebugSources UP-TO-DATE
:app:processDebugJavaRes UP-TO-DATE
:app:compileDebugJavaWithJavac UP-TO-DATE
:app:compileRetrolambdaDebug
:app:compileDebugNdk UP-TO-DATE
:app:compileDebugSources UP-TO-DATE
:app:preDexDebug
java.lang.RuntimeException: Exception parsing classes
at com.android.dx.command.dexer.Main.processClass(Main.java:752)
at com.android.dx.command.dexer.Main.processFileBytes(Main.java:718)
at com.android.dx.command.dexer.Main.access$1200(Main.java:85)
at com.android.dx.command.dexer.Main$FileBytesConsumer.processFileBytes(Main.java:1645)
at com.android.dx.cf.direct.ClassPathOpener.processArchive(ClassPathOpener.java:284)
at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:166)
at com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:144)
at com.android.dx.command.dexer.Main.processOne(Main.java:672)
at com.android.dx.command.dexer.Main.processAllFiles(Main.java:574)
at com.android.dx.command.dexer.Main.runMonoDex(Main.java:311)
at com.android.dx.command.dexer.Main.run(Main.java:277)
at com.android.dx.command.dexer.Main.main(Main.java:245)
at com.android.dx.command.Main.main(Main.java:106)
Caused by: com.android.dx.cf.iface.ParseException: bad class file magic (cafebabe) or version (0034.0000)
at com.android.dx.cf.direct.DirectClassFile.parse0(DirectClassFile.java:472)
at com.android.dx.cf.direct.DirectClassFile.parse(DirectClassFile.java:406)
at com.android.dx.cf.direct.DirectClassFile.parseToInterfacesIfNecessary(DirectClassFile.java:388)
at com.android.dx.cf.direct.DirectClassFile.getMagic(DirectClassFile.java:251)
at com.android.dx.command.dexer.Main.parseClass(Main.java:764)
at com.android.dx.command.dexer.Main.access$1500(Main.java:85)
at com.android.dx.command.dexer.Main$ClassParserTask.call(Main.java:1684)
at com.android.dx.command.dexer.Main.processClass(Main.java:749)
... 12 more
1 error; aborting
Error:Execution failed for task ':app:preDexDebug'.
com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command '/Library/Java/JavaVirtualMachines/jdk1.7.0_79.jdk/Contents/Home/bin/java'' finished with non-zero exit value 1
Information:BUILD FAILED
Information:Total time: 2.143 secs
Information:1 error
Information:0 warnings
Information:See complete output in console
我不能处理这个。有人能帮我吗?非常非常感谢:)
尝试将所有.java文件移到根包中。
这是我如何配置我的OSx环境,
-
编辑.bash_profile(位于您的主目录中)并添加以下行:
export JAVA_HOME=
/usr/libexec/java_home
export JAVA7_HOME=/usr/libexec/java_home -v 1.7
*现在"java -version"命令必须显示java 1.8,但retrolambda也可以访问java 7的主目录
-
将这些行添加到您的项目构建中。gradle文件:
{的依赖关系…类路径的me.tatarka: gradle-retrolambda: 3.2.5类路径"com.neenbedankt.gradle.plugins: android-apt: 1.8"
-
应用retrolambda插件到你的android应用模块build.gradle:
apply plugin: 'me.tatarka.retrolambda'