Android Studio 1.2 - Project encoding mismatches by default

后端 未结 4 1050
执笔经年
执笔经年 2020-12-03 09:59

I\'m a bit of an Android rookie, and I just upgraded to Android Studio 1.2. When I make a new project (API 16: Android 4.1 (Jelly Bean)), I immediately get the following war

4条回答
  •  死守一世寂寞
    2020-12-03 10:12

    Click File -> Settings (or click Ctrl + Alt + S) and find File Encodings in your Android Studio. See the image below as a reference.

    Now you have three options

    • Change project encoding to match UTF-8 since both Gradle and Android Lint use this (recommended),
    • or change IDE encoding to match other encoding,
    • or just simply ignore the warning. If it worked out for you so far, it will continue to work anyway


    (source: shrani.si)

    Once you see the warning, you can directly click on "Open File Encoding Settings" as shown in the image below. This will take you to the same place as described above.

    enter image description here

    You can also see the current encoding of your file at the bottom right corner of Android studio. You can also change it there. See the image below.

    IDE Encoding

    Also you can specify charset in your build.gradle script like this

    android {
        ...
        compileOptions {
            encoding "UTF-8"
            sourceCompatibility JavaVersion.VERSION_1_7
            targetCompatibility JavaVersion.VERSION_1_7
        }
    }
    

    According to Ashl7's comment, you need to do a gradle sync for this to work

提交回复
热议问题