Skip to content

Instantly share code, notes, and snippets.

@justasm
Last active May 15, 2020 17:55
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save justasm/4a75afd5f5f3e6ba0dbc16b5a1e5331b to your computer and use it in GitHub Desktop.
Save justasm/4a75afd5f5f3e6ba0dbc16b5a1e5331b to your computer and use it in GitHub Desktop.
Kotlin Android Extensions with Android library module https://youtrack.jetbrains.com/issue/KT-16934
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
applicationId "com.example.kxt"
minSdkVersion 15
targetSdkVersion 25
versionCode 1
versionName "1.0"
}
}
dependencies {
compile 'com.android.support:appcompat-v7:25.2.0'
compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
compile project(':library')
}
package com.example.kxt
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import kotlinx.android.synthetic.main.test.*
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.test)
image_view.scaleType = ImageView.ScaleType.CENTER
}
}
buildscript {
ext.kotlin_version = '1.1.0'
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
allprojects {
repositories {
jcenter()
}
}
apply plugin: 'com.android.library'
android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
minSdkVersion 15
targetSdkVersion 25
}
}
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/image_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
</FrameLayout>
@econBabar
Copy link

Not working getting unresolved reference error.

@niteshghn
Copy link

Any solution for this ?

@stimsoni9
Copy link

You need to be able to add
"apply plugin: 'kotlin-android'" and
"apply plugin: 'kotlin-android-extensions'"
to the libraries build.gradle

@yizems
Copy link

yizems commented Mar 8, 2019

not work ;

kotlin:1.3.21

@R00We
Copy link

R00We commented Apr 12, 2019

kotlin 1.3.30 still doesn't work. Move my common layouts in modules =(

@romaopedro
Copy link

Not working on 1.3.41 :'(

@HashemDeveloper
Copy link

Still it does not work v. 1.3.72

@justasm
Copy link
Author

justasm commented May 15, 2020

Yes, this is sample code for the issue reported over 3 years ago. The issue has been closed but the issue is not fixed, the latest issue tracking this can be found here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment