LoginSignup
4
1

More than 3 years have passed since last update.

ANDROID STUDIO KOTLIN ERROR : Cannot inline bytecode built with JVM target 1.8 into bytecode that is being built with JVM target 1.6. Please specify proper '-jvm-target' optio

Last updated at Posted at 2019-11-21

ENVIRONMENT
 - AndroidStudio3.5.2 アンドロイドスタジオ
 - KOTLIN コトリン
 - MinRequirementAPI lolipop22 /TestMachine Nexus6

ERROR Contents エラー内容

: Cannot inline bytecode built with JVM target 1.8 into bytecode that is being built with JVM target 1.6. Please specify proper '-jvm-target' option

新規にプロジェクトを構成し適当なテンプレートを選択してビルドすると上記エラーが出る場合があります。以下2ステップでエラーを解消できます。

STEP1 ターゲットJVMを1.8に変更します。

「ファイル」「設定」「Kotlinコンパイラー」を選択し、ターゲットJVMバージョンを1.6から1.8へ変更します。

0132.png

ターゲットJVMバージョンを1.6から1.8へ変更します。

STEP2 Gradleスクリプトのbuild.gradle(モジュール:app)を変更します。

build.gradle(モジュール:app)を変更します。

011.png

付与するコードは以下です。

  kotlinOptions {
    jvmTarget = '1.8'
  }

全体コードは以下です。

apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'

android {
    compileSdkVersion 29
    buildToolsVersion "29.0.2"
    defaultConfig {
        applicationId "com.."
        minSdkVersion 21
        targetSdkVersion 29
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    kotlinOptions {
        jvmTarget = '1.8'
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'androidx.core:core-ktx:1.1.0'
    implementation 'com.google.android.material:material:1.0.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    implementation 'androidx.navigation:navigation-fragment:2.1.0'
    implementation 'androidx.navigation:navigation-ui:2.1.0'
    implementation 'androidx.lifecycle:lifecycle-extensions:2.1.0'
    implementation 'androidx.navigation:navigation-fragment-ktx:2.1.0'
    implementation 'androidx.navigation:navigation-ui-ktx:2.1.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test.ext:junit:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}

ビルドが通ります

image.png

では

4
1
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
4
1