###AndroidStudioでjdk1.8使用時に文字化けが発生する
現在開発中のアプリでラムダ式を使用できるようにしたいと思い、jdk1.8に変更したらハードコーディングされている日本語の文字列が文字化けするようになってしまいました。
(以前jdk1.7を使用していた際には、文字化けせず表示されておりました。またString.xmlなどに記述した文字列は文字化けしません。)
どのように修正すればjdk1.8を使用しつつ、日本語の文字列をハードコーディングできるようになるでしょうか。
###文字化け内容
String hoge = "無"; 出力結果:辟。
(ソースコードはUTF-8で記述されているが、コンパイル時にSJISになってる?)
###試したこと
Build.gradle(project)に下記を追加(効果なし)
allprojects { repositories { jcenter() } tasks.withType(JavaCompile) { options.encoding = 'UTF-8' } }
###現在のbuild.gradle(app)
apply plugin: 'com.android.application' android { compileSdkVersion 25 buildToolsVersion "25.0.2" defaultConfig { //jdk1.8用に追加 jackOptions { enabled true } minSdkVersion 21 targetSdkVersion 25 versionCode 1 versionName "1.0" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } packagingOptions { exclude 'META-INF/NOTICE.txt' exclude 'META-INF/LICENSE.txt' exclude 'META-INF/DEPENDENCIES' exclude 'META-INF/NOTICE' exclude 'META-INF/LICENSE' } //jdk1.8用に追加 compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 } } dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) // for android compile 'com.android.support:appcompat-v7:25.+' compile 'com.android.support:design:25.+' // for common compile 'com.fasterxml.jackson.core:jackson-databind:latest.release' compile 'com.fasterxml.jackson.core:jackson-core:latest.release' compile 'com.fasterxml.jackson.core:jackson-annotations:latest.release' compile 'com.squareup.okhttp:okhttp:latest.release' compile 'com.squareup.okhttp:okhttp-urlconnection:latest.release' // for test testCompile 'junit:junit:4.12' androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { exclude group: 'com.android.support', module: 'support-annotations' }) }
###補足情報(言語/FW/ツール等のバージョンなど)
AndroidStudio2.2.3
回答3件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。