1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Android Studio Gradle でYou are currently using Java 6. の解決法

Posted at

起きたこと

Android Studio で古いプロジェクトを開いてGradleビルドしようとしたらエラー

Error:Gradle 3.3 requires Java 7 or later to run. You are currently using Java 6.

JDK 1.8 (8) はインストール済みだしプロジェクトのJDK設定もしている。
が、この上のエラーが消えない。

環境

Android Studio 1.5
MacOSX Yosemite 10.10.5

試したこと

Mac にJDK1.8 (8) は入っているし、環境変数JAVA_HOME もJDK1.8のpathに指定されている。
(再起動などもしてみた)

しかしエラーが取れなかった。

試しにGradle のバージョンをあげてみると、

Error:Failed to complete Gradle execution.

Cause:
Received fatal alert: protocol_version

Java 実行時に以下オプションで解決できるようだけど
通らず。
JAVA_TOOL_OPTIONS="-Dhttps.protocols=TLSv1.2"

解決策

というか回避策。

Gradle のバージョンを上げると、タイトルの通りJava 6 ではだめとなり、
なので、Java6でビルドが通る範囲でぎりぎりまでバージョンを下げてみる。

Java6 で実行する

Gradle とAndroid StudioのpluginであるGradle build tools
が関係しているようで

試してみると、Java6 で実行できるのは、
Gradle 2.x系 (<= Gradle 2.14.1) までのようで、
Gradle 2.14.1 を実行可能な Gradle build toolsのバージョンは =< Gradle 2.1.3 とのこと。

Java6 でGradleビルドする環境

つまり、
Java6 でビルド可能な最新バージョンの組み合わせは
Gradle 2.14.1
Gradle build tools 2.1.3

プロジェクトのGradle のバージョンを下げる

Projectのrootディレクトリで./gradlew を実行すると

$ chmod 755 gradlew
$ ./gradlew tasks
...
FAILURE: Build failed with an exception.

* Where:
Build file '/Users/user/AndroidStudio1.5Projects/RepeatingLocalNotifications/app/build.gradle' line: 1

* What went wrong:
A problem occurred evaluating project ':app'.
> Failed to apply plugin [id 'com.android.application']
   > Gradle version 2.14 is required. Current version is 3.3. If using the gradle wrapper, try editing the distributionUrl in /Users/user/AndroidStudio1.5Projects/RepeatingLocalNotifications/gradle/wrapper/gradle-wrapper.properties to gradle-2.2-all.zip

Gradle 2.14がrequiredとのこと。実際に2.14.+ だと通る。

./gradle/wrapper/gradle-wrapper.properties
# 以下に変更
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip
./app/build.gradle

buildscript {
    ...
    dependencies {
        classpath 'com.android.tools.build:gradle:2.1.3'
    }
}

repositoryを追加

(Java6とは関係ないが、依存ライブラリのためビルドを通すため。)

./build.gradle

allprojects {
    repositories {
        ...
        maven {
            url 'https://maven.google.com'
        }
    }
}

結論

いちおう通った。
(根本的な対処ではないが。)
古いMac (Yosemite 10.10.5) の環境のため、内部ライブラリ(Xcode build tools)の問題の可能性あり。

参考

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?