LoginSignup
4
2

More than 5 years have passed since last update.

Android Studioが「com.example.hogehoge.databindingは存在しません」「Invalid byte 3 of 3-byte UTF-8 sequence」エラーを吐くときの対処法

Last updated at Posted at 2018-04-02

ある日,他の人が作ったandroidアプリのソースをgithubを経由して自分のパソコンに持ってきて、いざビルドしようとしたら、android studio画面下部のMessage欄に

エラー: パッケージcom.example.hogehoge.databindingは存在しません

とかいうエラーメッセージが表示されてビルドできない。どうやらdatabindingがうまく動いていないらしい…?

そこでGradle Console欄も見てみた所、実は

> android.databinding.tool.util.LoggedErrorException: failure, see logs for details.
  Exception while handling step android.databinding.annotationprocessor.ProcessExpressions@186feb09 javax.xml.bind.UnmarshalException
   - with linked exception:
  [org.apache.xerces.impl.io.MalformedByteSequenceException: Invalid byte 3 of 3-byte UTF-8 sequence.]
    at javax.xml.bind.helpers.AbstractUnmarshallerImpl.createUnmarshalException(AbstractUnmarshallerImpl.java:333)
    at …
    at …

(中略)
    at …
    at …
Caused by: org.apache.xerces.impl.io.MalformedByteSequenceException: Invalid byte 3 of 3-byte UTF-8 sequence.
    at …
    at …

(以下略)

とかいうエラーメッセージが出ている。

さて、アプリ製作者の環境ではちゃんとビルド出来ているようなのに自分の環境ではなぜエラーが出てしまうのか…?Invalid byte 3 of 3-byte UTF-8 sequenceとは何…??

原因と解決方法

原因

製作者の開発環境がLinuxやMac OSだったアプリで、データバインディングを使用していて <layout>タグを使用していて且つソース中に直接日本語が使われているlayoutファイルが存在しているアプリのソースをwindowsに持ってきてビルドしようとするとこのエラーが出るらしい。

解決方法

日本語をすべてstringsファイルに移して@string/hogehogeで参照するように修正するとビルドできるようになります。

例:

  • 変更前

res/layout/activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<layout>
<data>
    <variable name="hoge" type="String"/>
</data>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/parent_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="こんにちは"/>
    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom"
        android:text="@{hoge}"/>


</android.support.design.widget.CoordinatorLayout>
</layout>

  • 変更後

res/values/strings.xml


<resources>
    <string name="hoge_str">こんにちは</string>
</resources>

res/layout/activity_main.xml


<?xml version="1.0" encoding="utf-8"?>
<layout>
<data>
    <variable name="hogehoge" type="String"/>
</data>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/parent_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@strings/hoge_str"/>
    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom"
        android:text="@{hogehoge}"/>


</android.support.design.widget.CoordinatorLayout>
</layout>

後日談

android studioのバージョンを3.1.4にアップデートしたらこのエラー出なくなりました。
やはりandroid studio側のbugだったらしい…。修正に感謝。

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