2
2

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のレイアウトプレビューがエラーで埋め尽くされた

Posted at

MacでAndroid Studioを使っていたらある日xmlレイアウトのプレビューが見たことないエラーで埋め尽くされるようになりました。
今までは再起動やキャッシュの消去で治りましたが、今回は治らなかったので原因を調べて解決しました。

原因

retrolambdaを使ってラムダ式を使った独自ビューを表示しようとしていたことでした。
Android StudioはJDK1.8を使っていましたが、プレビューのところだけそれが効いてないらしかったので以下の方法で解決しました。

解決策

以下はYosemite以降のMacの場合です。
結論から言うとlaunchctlでsetenvでSTUDIO_JDKの値を設定すればOKなんですが、これをMacに設定する方法にむしろ自分はつまずきました。
~/Library/LaunchAgents/に以下のファイルを作成します。

STUDIO_JDK.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
    <dict>
        <key>Label</key>
        <string>setenv.STUDIO_JDK</string>

        <key>ProgramArguments</key>
        <array>
            <string>/bin/launchctl</string>
            <string>setenv</string>
            <string>STUDIO_JDK</string>
            <string>JDKの置き場所</string>
        </array>

        <key>RunAtLoad</key>
        <true/>

        <key>ServiceIPC</key>
        <false/>
    </dict>
</plist>

これでMacを再起動すればOKです。すぐ反映させる場合は、

launchctl load STUDIO_JDK.plist
2
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
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?