kotlin-android-extensions

Kotlin,Java,multidex,Dagger 2,Butterknife and Realm: transformClassesWithJarMergingForDebug: duplicate entry: org/jetbrains/annotations/NotNull.class

扶醉桌前 提交于 2019-12-05 10:07:17
We have existing Java Android code. We want to painlessly slowly start moving to Kotlin. We use Dagger 2, Butterknife and Realm. We use Java 8 compiler (but our targetCompatibility and sourceCompatibility are 1.7). I've been roaming the web for hours, seen SO, GitHub conversations and so on, and managed to solve all problems except one: The build is successful, but when trying to debug, we get: Error:Execution failed for task ':app:transformClassesWithJarMergingForDebug'. > com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: org/jetbrains

Referencing views with the same id in different layouts with kotlin android extensions

社会主义新天地 提交于 2019-12-05 03:49:19
In my Android project I have two layouts: num_info and num_info_pack. Both have views with id "circle". So I thought referencing those views by layout_name.circle would solve the problem: val inetView = activity.layoutInflater.inflate(R.layout.num_info_pack, parent, false) inetView.circle.setBackgroundResource(background) But circle is underlined with red and it says: Overload resolution ambiguity. All these functions match. public val View.circle: View! defined in kotlinx.android.synthetic.main.num_info_pack.view public val View.circle: RelativeLayout! defined in kotlinx.android.synthetic

Extremely slow in autocompletion & code analysis for Kotlin projects in Intellij IDEA

半城伤御伤魂 提交于 2019-12-05 03:28:17
We have a project on IDEA that consists of a couple med sized Java packages and one very small Kotlin package (5 files). I noticed performance is fine with any Java packages, but it's 10x slower in autocompletion, code analysis and compilation for the very small Kotlin package. Autocompletion occasionally was so slow to a point where the popover couldn't load all the methods and it had to load a couple API incrementally. Every time our developer types a word and wait for autocomplete, it takes about 2-5 seconds for the expected autocomplete to show up. Sometimes autocomplete was too slow to

Varargs Kotlin Java interop not working properly

被刻印的时光 ゝ 提交于 2019-12-05 01:24:21
For the makeSceneTransitionAnimation there are two static functions public static ActivityOptionsCompat makeSceneTransitionAnimation(Activity activity, View sharedElement, String sharedElementName) and public static ActivityOptionsCompat makeSceneTransitionAnimation(Activity activity, Pair<View, String>... sharedElements) The first function call works properly in Kotlin but when calling the second one, both these calls return errors val imageTransition = Pair<View, String>(imageView, imageView.getTransitionName()); val textTransition = Pair<View, String>(textView, textView.getTransitionName())

Kotlin Android Extension layouts from library module cannot be resolved

倾然丶 夕夏残阳落幕 提交于 2019-12-04 23:11:40
I have my buyer , seller module and a common module. Few layouts which are used in both buyer and seller module are placed in common module. common -> layout_toolbar.xml buyer -> activity_sell.xml -> <LinearLayout> <include layout="@layout/layout_toolbar" /> <!-- layout_toolbar.xml is from common module --> </LinearLayout> seller -> activity_buy.xml -> <RelativeLayout> <include layout="@layout/layout_toolbar" /> <!-- layout_toolbar.xml is from common module --> </RelativeLayout> buyer -> BuyActivity.kt toolbar.title = "Buy" seller -> SellActivity.kt toolbar.title = "Sell" Everything works fine

Kotlin synthetic and custom layout in DialogFragment

允我心安 提交于 2019-12-04 22:26:41
Let's say I have this layout: <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <ImageButton android:id="@+id/add_dep_btn" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentEnd="true" android:layout_alignParentRight="true" android:layout_marginEnd="5dp" android:layout_marginRight="5dp" android:src="@android:drawable/ic_input_add" /> <EditText android:id="@+id/add_dep_text"

How to use Parcel.readTypedList() along with @Parcelize from kotlin-android-extensions?

偶尔善良 提交于 2019-12-04 04:35:17
问题 I'm running into a problem with implementing Parcelable-based state persistence in a View. Namely, as I need to implement the methods of BaseSavedState like this: class SavedState : BaseSavedState { lateinit var myList: ArrayList<MyParcelable> constructor(superState: Parcelable) : super(superState) {} private constructor(parcel: Parcel) : super(parcel) { val listSize = parcel.readInt() val list = ArrayList<MyParcelable>(listSize) this.myList = parcel.readTypedList(list, /* needs MyParcelable

Kotlin Android debounce

你。 提交于 2019-12-03 12:03:28
Is there any fancy way to implement debounce logic with Kotlin Android? I'm not using Rx in project. There is a way in Java , but it is too big as for me here. You can use kotlin coroutines to achieve that. Here is an example . Be aware that coroutines are experimental at kotlin 1.1+ and it may be changed in upcoming kotlin versions. UPDATE Since Kotlin 1.3 release, coroutines are now stable. Thanks to https://medium.com/@pro100svitlo/edittext-debounce-with-kotlin-coroutines-fd134d54f4e9 and https://stackoverflow.com/a/50007453/2914140 I wrote this code: private var textChangedJob: Job? = null

How to add an item to an ArrayList in Kotlin?

核能气质少年 提交于 2019-12-03 06:28:00
问题 How to add an item to an ArrayList in Kotlin? 回答1: If you have a MUTABLE collection: val list = mutableListOf(1, 2, 3) list += 4 If you have an IMMUTABLE collection: var list = listOf(1, 2, 3) list += 4 note that I use val for the mutable list to emphasize that the object is always the same, but its content changes. In case of the immutable list, you have to make it var . A new object is created by the += operator with the additional value. 回答2: For people just migrating from java , In Kotlin

What's Kotlin Backing Field For?

与世无争的帅哥 提交于 2019-12-03 00:35:15
问题 As a Java developer, the concept of a backing field is a bit foreign to me. Given: class Sample { var counter = 0 // the initializer value is written directly to the backing field set(value) { if (value >= 0) field = value } } What's this backing field good for? Kotlin docs said: Classes in Kotlin cannot have fields. However, sometimes it is necessary to have a backing field when using custom accessors . Why? Whats the difference with using the properties name itself inside the setter, eg.