我试图在Android Studio中试用Kotlin和Kotlin Android扩展程序.我已经在Ubuntu 14.04上的Android Studio v 1.5.1和OS X El Capitan上的Android Studio v 1.5.1中尝试了这一点,结果相同.
这是我在做的事情:
然后我进入生成的content_main.xml文件并为"Hello World!"添加一个id(hello).TextView中.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="com.gmail.npnster.mykotlinfirstproject.MainActivity"
tools:showIn="@layout/activity_main">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
android:id="@+id/hello"
/>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
然后在转换后的MainActivity中添加一行来设置TextView.(如下所示).Android Studio然后提示我(通过alt-enter)插入此行(也显示如下)
import kotlinx.android.synthetic.main.content_main.*
Run Code Online (Sandbox Code Playgroud)
所以在这一点一切似乎罚款
但是当我尝试编译这个时,我得到了
Unresolved reference: kotlinx
Unresolved reference: kotlinx
Unresolved reference: hello
Run Code Online (Sandbox Code Playgroud)
注意,我并没有安装科特林的Android扩展插件.截至几天前,现在应该将其包含在主插件中并标记为已过时.(事实上,如果您在使用最新插件时尝试安装它,则不会安装任何新内容)
有谁看到我做错了什么?
主要活动
import android.os.Bundle
import android.support.design.widget.FloatingActionButton
import android.support.design.widget.Snackbar
import android.support.v7.app.AppCompatActivity
import android.support.v7.widget.Toolbar
import android.view.View
import …Run Code Online (Sandbox Code Playgroud)