Update android projects used in AGP integration tests.

This commit is contained in:
Mads Ager
2022-09-16 07:56:43 +02:00
committed by Alexander Udalov
parent 294395f4cc
commit b2dc2ed0be
73 changed files with 21 additions and 912 deletions
-8
View File
@@ -1,8 +0,0 @@
import android.view.*
import android.app.*
import android.widget.*
import kotlinx.android.synthetic.main.layout.*
class MyActivity : Activity() {
init { textView.setText("Some text") }
}
@@ -1,9 +0,0 @@
-d
$TEMP_DIR$
-Xplugin=dist/kotlinc/lib/android-extensions-compiler.jar
-P
plugin\:org.jetbrains.kotlin.android\:package=com.myapp
-P
plugin\:org.jetbrains.kotlin.android\:variant=main;$TESTDATA_DIR$/../androidPlugin/res
$TESTDATA_DIR$/pluginSimple.kt
$TESTDATA_DIR$/../androidPlugin
@@ -1 +0,0 @@
OK
@@ -1,5 +0,0 @@
-d
$TEMP_DIR$
-Xcompiler-plugin=dist/kotlinc/lib/android-extensions-compiler.jar=package=com.myapp,variant=main;$TESTDATA_DIR$/../androidPlugin/res
$TESTDATA_DIR$/pluginSimple.kt
$TESTDATA_DIR$/../androidPlugin
@@ -1,2 +0,0 @@
error: -Xcompiler-plugin argument is allowed only for for K2 compiler. Please use -Xplugin argument or enable -Xuse-k2
COMPILATION_ERROR
@@ -1,8 +0,0 @@
import android.view.*
import android.app.*
import android.widget.*
import kotlinx.android.synthetic.main.layout.*
class MyActivity : Activity() {
init { textView.setText("Some text") }
}
@@ -1,10 +0,0 @@
-d
$TEMP_DIR$
-Xplugin=dist/kotlinc/lib/android-extensions-compiler.jar
-P
plugin\:org.jetbrains.kotlin.android\:package=com.myapp
-P
plugin\:org.jetbrains.kotlin.android\:variant=main;$TESTDATA_DIR$/../androidPlugin/res
$TESTDATA_DIR$/pluginSimple.kt
$TESTDATA_DIR$/../androidPlugin
-Xuse-k2
@@ -1,7 +0,0 @@
warning: ATTENTION!
This build uses experimental K2 compiler:
-Xuse-k2
error: there are some plugins incompatible with K2 compiler:
org.jetbrains.kotlin.android.synthetic.AndroidComponentRegistrar
Please remove -Xuse-k2
COMPILATION_ERROR
@@ -1,6 +0,0 @@
-d
$TEMP_DIR$
-Xcompiler-plugin=dist/kotlinc/lib/android-extensions-compiler.jar=package=com.myapp,variant=main;$TESTDATA_DIR$/../androidPlugin/res
$TESTDATA_DIR$/pluginSimple.kt
$TESTDATA_DIR$/../androidPlugin
-Xuse-k2
@@ -1,7 +0,0 @@
warning: ATTENTION!
This build uses experimental K2 compiler:
-Xuse-k2
error: there are some plugins incompatible with K2 compiler:
org.jetbrains.kotlin.android.synthetic.AndroidComponentRegistrar
Please remove -Xuse-k2
COMPILATION_ERROR
@@ -103,26 +103,6 @@ public class CliTestGenerated extends AbstractCliTest {
public void testNoPluginInClasspath() throws Exception {
runTest("compiler/testData/cli/jvm/plugins/noPluginInClasspath.args");
}
@TestMetadata("pluginSimple_legacy.args")
public void testPluginSimple_legacy() throws Exception {
runTest("compiler/testData/cli/jvm/plugins/pluginSimple_legacy.args");
}
@TestMetadata("pluginSimple_modern_noK2.args")
public void testPluginSimple_modern_noK2() throws Exception {
runTest("compiler/testData/cli/jvm/plugins/pluginSimple_modern_noK2.args");
}
@TestMetadata("pluginWithK2Error_legacy.args")
public void testPluginWithK2Error_legacy() throws Exception {
runTest("compiler/testData/cli/jvm/plugins/pluginWithK2Error_legacy.args");
}
@TestMetadata("pluginWithK2Error_modern.args")
public void testPluginWithK2Error_modern() throws Exception {
runTest("compiler/testData/cli/jvm/plugins/pluginWithK2Error_modern.args");
}
}
@TestMetadata("compiler/testData/cli/jvm")
@@ -69,7 +69,6 @@ dependencies {
testImplementation(project(path = ":examples:annotation-processor-example"))
testImplementation(kotlinStdlib("jdk8"))
testImplementation(project(":kotlin-android-extensions"))
testImplementation(project(":kotlin-parcelize-compiler"))
testImplementation(commonDependency("org.jetbrains.intellij.deps", "trove4j"))
testImplementation(commonDependency("io.ktor", "ktor-server-test-host"))
@@ -82,7 +81,6 @@ dependencies {
testImplementation(commonDependency("com.google.code.gson:gson"))
testApiJUnit5(vintageEngine = true, jupiterParams = true)
testRuntimeOnly(project(":kotlin-android-extensions"))
testRuntimeOnly(project(":compiler:tests-mutes"))
// Workaround for missing transitive import of the common(project `kotlin-test-common`
@@ -270,28 +270,6 @@ open class KotlinAndroid36GradleIT : KotlinAndroid3GradleIT() {
assertFileExists("app/build/tmp/kotlin-classes/$variant/com/example/app/AKt.class")
assertFileExists("app/build/tmp/kotlin-classes/$variant/com/example/app/KtUsageKt.class")
}
// Check that Android extensions arguments are available only in the Android source sets:
val compilerPluginArgsRegex = "(\\w+)${Regex.escape("=args=>")}(.*)".toRegex()
val compilerPluginOptionsBySourceSet =
compilerPluginArgsRegex.findAll(output).associate { it.groupValues[1] to it.groupValues[2] }
compilerPluginOptionsBySourceSet.entries.forEach { (sourceSetName, argsString) ->
val shouldHaveAndroidExtensionArgs = sourceSetName.startsWith("androidApp") &&
(androidGradlePluginVersion < AGPVersion.v7_0_0 || !sourceSetName.contains("AndroidTestRelease")) &&
(androidGradlePluginVersion < AGPVersion.v7_1_0 || !sourceSetName.contains("androidAppTestFixtures"))
if (shouldHaveAndroidExtensionArgs)
assertTrue("$sourceSetName is an Android source set and should have Android Extensions in the args") {
"plugin:org.jetbrains.kotlin.android" in argsString
}
else
assertEquals(
"[]",
argsString,
"$sourceSetName is not an Android source set and should not have Android Extensions in the args"
)
}
}
val groupDir = "lib/build/repo/com/example/"
@@ -704,16 +682,6 @@ open class KotlinAndroid70GradleIT : KotlinAndroid36GradleIT() {
}
}
@Test
fun testNamespaceDSLInsteadOfPackageAttributeInManifest() {
val project = Project("AndroidExtensionsProjectAGP7")
val options = defaultBuildOptions().copy(incremental = false)
project.build("assembleDebug", options = options) {
assertSuccessful()
assertContains("The 'kotlin-android-extensions' Gradle plugin is deprecated")
}
}
}
open class KotlinAndroid71GradleIT : KotlinAndroid70GradleIT() {
@@ -1024,42 +992,6 @@ abstract class AbstractKotlinAndroidGradleTests : BaseGradleIT() {
}
}
// KT-51177: when experimental flag is enabled
@Test
fun testIncrementalBuildAfterResourceChangeAndroidExtensions() {
val project = Project("AndroidExtensionsProject")
project.setupWorkingDir()
project.projectDir.resolve("app/build.gradle").appendText(
"""
|
|androidExtensions {
| experimental = true
|}
|
""".trimMargin()
)
project.build("assembleDebug") {
assertSuccessful()
assertTasksExecuted(":app:compileDebugKotlin")
}
project.projectDir
.resolve("app/src/main/res/layout/activity_main.xml")
.modify {
it.replace("android:layout_width=\"wrap_content\"", "android:layout_width=\"match_parent\"")
}
project.build("assembleDebug") {
assertSuccessful()
assertTasksExecuted(":app:compileDebugKotlin")
assertContainsRegex(
"compilerMode=INCREMENTAL_COMPILER.*areFileChangesKnown=true.*app/build/kotlin".toRegex()
)
}
}
@Test
fun testAndroidDaggerIC() {
val project = Project("AndroidDaggerProject")
@@ -1108,17 +1040,6 @@ abstract class AbstractKotlinAndroidGradleTests : BaseGradleIT() {
}
}
@Test
fun testAndroidExtensions() {
val project = Project("AndroidExtensionsProject")
val options = defaultBuildOptions().copy(incremental = false)
project.build("assembleDebug", options = options) {
assertSuccessful()
assertContains("The 'kotlin-android-extensions' Gradle plugin is deprecated")
}
}
@Test
fun testParcelize() {
val project = Project("AndroidParcelizeProject")
@@ -1129,65 +1050,6 @@ abstract class AbstractKotlinAndroidGradleTests : BaseGradleIT() {
}
}
@Test
fun testAndroidExtensionsIncremental() {
val project = Project("AndroidExtensionsProject")
val options = defaultBuildOptions().copy(incremental = true, useClasspathSnapshot = true)
project.build("assembleDebug", options = options) {
assertSuccessful()
val affectedSources = project.projectDir.getFilesByNames(
"MyActivity.kt", "noLayoutUsages.kt"
)
val relativePaths = project.relativize(affectedSources)
assertCompiledKotlinSources(relativePaths)
}
val activityLayout = File(project.projectDir, "app/src/main/res/layout/activity_main.xml")
activityLayout.modify { it.replace("textView", "newTextView") }
project.build("assembleDebug", options = options) {
assertFailed()
val affectedSources = project.projectDir.getFilesByNames("MyActivity.kt")
val relativePaths = project.relativize(affectedSources)
assertCompiledKotlinSources(relativePaths)
}
}
@Test
fun testAndroidExtensionsManyVariants() {
val project = Project("AndroidExtensionsManyVariants")
val options = defaultBuildOptions().copy(incremental = false)
project.build("assemble", options = options) {
assertSuccessful()
}
}
@Test
fun testAndroidExtensionsSpecificFeatures() {
val project = Project("AndroidExtensionsSpecificFeatures")
val options = defaultBuildOptions().copy(incremental = false)
project.build("assemble", options = options) {
assertFailed()
assertContains("Unresolved reference: textView")
}
File(project.projectDir, "app/build.gradle").modify { it.replace("[\"parcelize\"]", "[\"views\"]") }
project.build("assemble", options = options) {
assertFailed()
assertContainsRegex("Class 'User' is not abstract and does not implement abstract member public abstract fun (writeToParcel|describeContents)".toRegex())
}
File(project.projectDir, "app/build.gradle").modify { it.replace("[\"views\"]", "[\"parcelize\", \"views\"]") }
project.build("assemble", options = options) {
assertSuccessful()
}
}
@Test
fun shouldAllowToApplyPluginWhenAndroidPluginIsMissing() {
with(Project("simpleProject", minLogLevel = LogLevel.WARN)) {
@@ -208,46 +208,6 @@ class BuildCacheRelocationIT : KGPBaseTest() {
)
}
@AndroidGradlePluginTests
@DisplayName("KT-48849: Kotlin compile should ignore empty layout resource directories added by kotlin android extensions")
@GradleTestVersions(minVersion = TestVersions.Gradle.G_6_8)
@AndroidTestVersions(minVersion = TestVersions.AGP.AGP_42)
@GradleAndroidTest
fun compileIgnoreEmptyAndroidResLayoutDirs(
gradleVersion: GradleVersion,
agpVersion: String,
jdkProvider: JdkVersions.ProvidedJdk
) {
val (firstProject, secondProject) = prepareTestProjects(
"AndroidExtensionsProject",
gradleVersion,
defaultBuildOptions.copy(androidVersion = agpVersion),
jdkProvider.location
) {
it.subProject("app").buildGradle.append(
"""
|
|androidExtensions {
| experimental = true
|}
""".trimMargin()
)
}
firstProject
.subProject("app")
.projectPath
.resolve("src/main/res/layout-ar")
.createDirectory()
checkBuildCacheRelocation(
firstProject,
secondProject,
listOf("assembleDebug"),
listOf(":app:compileDebugKotlin")
)
}
@NativeGradlePluginTests
@DisplayName("with native project")
@GradleTest
@@ -14,7 +14,7 @@ buildscript {
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-parcelize'
android {
compileSdkVersion 23
@@ -20,11 +20,11 @@ import android.content.Intent
import android.location.LocationManager
import android.os.Bundle
import android.os.Parcelable
import android.widget.TextView
import com.example.dagger.kotlin.DemoActivity
import com.example.dagger.kotlin.DemoApplication
import com.example.dagger.kotlin.R
import kotlinx.android.parcel.Parcelize
import kotlinx.android.synthetic.main.activity_main.locationInfo
import kotlinx.parcelize.Parcelize
import javax.inject.Inject
class HomeActivity : DemoActivity() {
@@ -37,7 +37,7 @@ class HomeActivity : DemoActivity() {
(application as DemoApplication).component.inject(this)
// TODO do something with the injected dependencies here!
locationInfo.text = "Injected LocationManager:\n$locationManager"
(findViewById(R.id.locationInfo) as TextView).text = "Injected LocationManager:\n$locationManager"
}
}
@@ -1,56 +0,0 @@
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 23
buildToolsVersion "25.0.2"
defaultConfig {
applicationId "org.example.manyvariants"
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
}
}
// Needed for older AGP. It can be removed when the lowest supported AGP version is 4.2.0 or newer.
compileOptions {
sourceCompatibility 1.8
targetCompatibility 1.8
}
flavorDimensions "color"
productFlavors {
demo {
dimension "color"
applicationIdSuffix ".demo"
versionNameSuffix "-demo"
}
full {
dimension "color"
applicationIdSuffix ".full"
versionNameSuffix "-full"
}
}
lintOptions {
checkReleaseBuilds false
abortOnError false
}
}
androidExtensions {
experimental = true
features = ["views", "parcelize"]
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
}
@@ -1,10 +0,0 @@
package org.example.manyvariants
import android.app.Activity
import kotlinx.android.synthetic.debug.activity_debug.*
import kotlinx.android.synthetic.main.activity_main.*
fun Activity.debug() {
viewMain
viewDebug
}
@@ -1,11 +0,0 @@
<?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">
<TextView
android:id="@+id/viewDebug"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</RelativeLayout>
@@ -1,10 +0,0 @@
package org.example.manyvariants
import android.app.Activity
import kotlinx.android.synthetic.demo.activity_demo.*
import kotlinx.android.synthetic.main.activity_main.*
fun Activity.demo() {
viewMain
viewDemo
}
@@ -1,11 +0,0 @@
<?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">
<TextView
android:id="@+id/viewDemo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</RelativeLayout>
@@ -1,14 +0,0 @@
package org.example.manyvariants
import android.app.Activity
import kotlinx.android.synthetic.debug.activity_debug.*
import kotlinx.android.synthetic.demo.activity_demo.*
import kotlinx.android.synthetic.demoDebug.activity_demo_debug.*
import kotlinx.android.synthetic.main.activity_main.*
fun Activity.demoDebug() {
viewMain
viewDemo
viewDebug
viewDemoDebug
}
@@ -1,11 +0,0 @@
<?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">
<TextView
android:id="@+id/viewDemoDebug"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</RelativeLayout>
@@ -1,10 +0,0 @@
package org.example.manyvariants
import android.app.Activity
import kotlinx.android.synthetic.full.activity_full.*
import kotlinx.android.synthetic.main.activity_main.*
fun Activity.full() {
viewMain
viewFull
}
@@ -1,11 +0,0 @@
<?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">
<TextView
android:id="@+id/viewFull"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</RelativeLayout>
@@ -1,14 +0,0 @@
package org.example.manyvariants
import android.app.Activity
import kotlinx.android.synthetic.full.activity_full.*
import kotlinx.android.synthetic.fullRelease.activity_full_release.*
import kotlinx.android.synthetic.main.activity_main.*
import kotlinx.android.synthetic.release.activity_release.*
fun Activity.fullRelease() {
viewMain
viewFull
viewRelease
viewFullRelease
}
@@ -1,11 +0,0 @@
<?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">
<TextView
android:id="@+id/viewFullRelease"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</RelativeLayout>
@@ -1,15 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.example.manyvariants">
<application android:allowBackup="true" android:supportsRtl="true">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
</manifest>
@@ -1,18 +0,0 @@
package org.example.manyvariants
import android.app.Activity
import android.os.Bundle
import kotlinx.android.synthetic.main.activity_main.*
import kotlinx.android.parcel.Parcelize
import android.os.Parcelable
class MainActivity : Activity() {
override fun onCreate(savedInstanceState: Bundle) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
viewMain
}
}
@Parcelize
class User(val firstName: String, val lastName: String) : Parcelable
@@ -1,11 +0,0 @@
<?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">
<TextView
android:id="@+id/viewMain"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</RelativeLayout>
@@ -1,10 +0,0 @@
package org.example.manyvariants
import android.app.Activity
import kotlinx.android.synthetic.release.activity_release.*
import kotlinx.android.synthetic.main.activity_main.*
fun Activity.release() {
viewMain
viewRelease
}
@@ -1,11 +0,0 @@
<?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">
<TextView
android:id="@+id/viewRelease"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</RelativeLayout>
@@ -1,25 +0,0 @@
buildscript {
repositories {
mavenLocal()
maven { url 'https://maven.google.com' }
mavenCentral()
maven { url = uri("https://jcenter.bintray.com/") }
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "com.android.tools.build:gradle:$android_tools_version"
}
}
allprojects {
repositories {
mavenLocal()
maven { url 'https://maven.google.com' }
mavenCentral()
maven { url = uri("https://jcenter.bintray.com/") }
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
@@ -1,30 +0,0 @@
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 23
buildToolsVersion "25.0.2"
defaultConfig {
applicationId "com.example.dagger.kotlin"
minSdkVersion 14
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
// Needed for older AGP. It can be removed when the lowest supported AGP version is 4.2.0 or newer.
compileOptions {
sourceCompatibility 1.8
targetCompatibility 1.8
}
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
}
@@ -1,16 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.androidextensions">
<application android:label="app_name">
<activity
android:label="app_name"
android:name="com.example.androidextensions.MyActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
</application>
</manifest>
@@ -1,31 +0,0 @@
/*
* Copyright 2010-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.example.androidextensions
import android.os.Bundle
import android.app.Activity
import kotlinx.android.synthetic.main.activity_main.textView
class HomeActivity : Activity() {
override fun onCreate(savedInstanceState: Bundle?) {
myUtilFunction()
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
this.textView.setText("Hello, world!")
}
}
@@ -1,9 +0,0 @@
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
@@ -1,3 +0,0 @@
<resources>
<string name="app_name">kotlin</string>
</resources>
@@ -1,24 +0,0 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
mavenLocal()
maven { url 'https://maven.google.com' }
mavenCentral()
maven { url = uri("https://jcenter.bintray.com/") }
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "com.android.tools.build:gradle:$android_tools_version"
}
}
allprojects {
repositories {
mavenLocal()
maven { url 'https://maven.google.com' }
mavenCentral()
maven { url = uri("https://jcenter.bintray.com/") }
}
}
@@ -1,25 +0,0 @@
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 23
buildToolsVersion "25.0.2"
namespace "com.example.androidextensions"
defaultConfig {
applicationId "com.example.dagger.kotlin"
minSdkVersion 14
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
}
@@ -1,16 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<application android:label="app_name">
<activity
android:label="app_name"
android:name="com.example.androidextensions.MyActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
</application>
</manifest>
@@ -1,31 +0,0 @@
/*
* Copyright 2010-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.example.androidextensions
import android.os.Bundle
import android.app.Activity
import kotlinx.android.synthetic.main.activity_main.textView
class HomeActivity : Activity() {
override fun onCreate(savedInstanceState: Bundle?) {
myUtilFunction()
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
this.textView.setText("Hello, world!")
}
}
@@ -1,9 +0,0 @@
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
@@ -1,3 +0,0 @@
<resources>
<string name="app_name">kotlin</string>
</resources>
@@ -1,24 +0,0 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
mavenLocal()
maven { url 'https://maven.google.com' }
mavenCentral()
maven { url = uri("https://jcenter.bintray.com/") }
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "com.android.tools.build:gradle:$android_tools_version"
}
}
allprojects {
repositories {
mavenLocal()
maven { url 'https://maven.google.com' }
mavenCentral()
maven { url = uri("https://jcenter.bintray.com/") }
}
}
@@ -1,40 +0,0 @@
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 23
buildToolsVersion "25.0.2"
defaultConfig {
applicationId "com.example.dagger.kotlin"
minSdkVersion 14
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
// Needed for older AGP. It can be removed when the lowest supported AGP version is 4.2.0 or newer.
compileOptions {
sourceCompatibility 1.8
targetCompatibility 1.8
}
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
lintOptions {
checkReleaseBuilds false
abortOnError false
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
}
androidExtensions {
experimental = true
features = ["parcelize"]
}
@@ -1,16 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.androidextensions">
<application android:label="app_name">
<activity
android:label="app_name"
android:name="com.example.androidextensions.MyActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
</application>
</manifest>
@@ -1,35 +0,0 @@
/*
* Copyright 2010-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.example.androidextensions
import android.os.Bundle
import android.app.Activity
import kotlinx.android.synthetic.main.activity_main.textView
import kotlinx.android.parcel.Parcelize
import android.os.Parcelable
class HomeActivity : Activity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
this.textView.setText("Hello, world!")
}
}
@Parcelize
class User(val firstName: String, val lastName: String) : Parcelable
@@ -1,9 +0,0 @@
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
@@ -1,3 +0,0 @@
<resources>
<string name="app_name">kotlin</string>
</resources>
@@ -1,24 +0,0 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
mavenLocal()
maven { url 'https://maven.google.com' }
mavenCentral()
maven { url = uri("https://jcenter.bintray.com/") }
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "com.android.tools.build:gradle:$android_tools_version"
}
}
allprojects {
repositories {
mavenLocal()
maven { url 'https://maven.google.com' }
mavenCentral()
maven { url = uri("https://jcenter.bintray.com/") }
}
}
@@ -7,14 +7,12 @@ buildscript {
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "org.jetbrains.kotlin:kotlin-android-extensions:$kotlin_version"
classpath 'com.android.tools.build:gradle:' + android_tools_version
}
}
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 23
@@ -32,5 +32,4 @@ android {
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation "org.jetbrains.kotlin:kotlin-android-extensions-runtime:$kotlin_version"
}
@@ -1,7 +1,6 @@
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 23
@@ -17,10 +17,10 @@ package com.example.dagger.kotlin.ui
import android.location.LocationManager
import android.os.Bundle
import android.widget.TextView
import com.example.dagger.kotlin.DemoActivity
import com.example.dagger.kotlin.DemoApplication
import com.example.dagger.kotlin.R
import kotlinx.android.synthetic.main.activity_main.locationInfo
import javax.inject.Inject
class HomeActivity : DemoActivity() {
@@ -33,7 +33,7 @@ class HomeActivity : DemoActivity() {
(application as DemoApplication).component.inject(this)
// TODO do something with the injected dependencies here!
locationInfo.text = "Injected LocationManager:\n$locationManager"
(findViewById(R.id.locationInfo) as TextView).text = "Injected LocationManager:\n$locationManager"
}
inner class InnerClass
@@ -1,7 +1,6 @@
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 27
@@ -1,6 +1,5 @@
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
android {
@@ -5,7 +5,7 @@ import android.graphics.BitmapFactory
import android.os.Build
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import kotlinx.android.synthetic.main.activity_main.*
import android.support.v7.widget.Toolbar
import mobi.porquenao.poc.kotlin.R
abstract class BaseActivity : AppCompatActivity() {
@@ -17,7 +17,7 @@ abstract class BaseActivity : AppCompatActivity() {
override fun setContentView(layoutResID: Int) {
super.setContentView(layoutResID)
setSupportActionBar(toolbar)
setSupportActionBar(findViewById(R.id.toolbar) as Toolbar)
}
private fun prepareTaskDescription() {
@@ -2,9 +2,9 @@ package mobi.porquenao.poc.kotlin.ui
import android.os.Bundle
import android.support.v7.widget.LinearLayoutManager
import android.support.v7.widget.RecyclerView
import android.view.Menu
import android.view.MenuItem
import kotlinx.android.synthetic.main.activity_main.*
import mobi.porquenao.poc.kotlin.R
class MainActivity : BaseActivity() {
@@ -14,7 +14,7 @@ class MainActivity : BaseActivity() {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
with (list) {
with (findViewById(R.id.list) as RecyclerView) {
setHasFixedSize(true)
layoutManager = LinearLayoutManager(this@MainActivity)
listAdapter = MainAdapter()
@@ -29,7 +29,7 @@ class MainActivity : BaseActivity() {
override fun onOptionsItemSelected(item: MenuItem?): Boolean {
listAdapter.add()
list.smoothScrollToPosition(0)
(findViewById(R.id.list) as RecyclerView).smoothScrollToPosition(0)
return true
}
@@ -1,12 +1,14 @@
package mobi.porquenao.poc.kotlin.ui
import android.graphics.Color
import android.support.v7.widget.CardView
import android.support.v7.widget.RecyclerView
import android.text.format.DateFormat
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import kotlinx.android.synthetic.main.main_item.view.*
import android.widget.TextView
import android.widget.LinearLayout
import mobi.porquenao.poc.kotlin.R
import mobi.porquenao.poc.kotlin.core.Item
import mobi.porquenao.poc.kotlin.core.ItemRepository
@@ -59,9 +61,9 @@ class MainAdapter : RecyclerView.Adapter<MainAdapter.ViewHolder>() {
}
class ViewHolder(view: View) : RecyclerView.ViewHolder(view) {
val card = view.card
val container = view.container
val title = view.title
val date = view.date
val card = view.findViewById(R.id.card) as CardView
val container = view.findViewById(R.id.container) as LinearLayout
val title = view.findViewById(R.id.title) as TextView
val date = view.findViewById(R.id.date) as TextView
}
}
@@ -19,7 +19,6 @@ buildscript {
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'realm-android'
android {
@@ -14,7 +14,6 @@ buildscript {
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'androidx.navigation.safeargs'
android {
@@ -7,10 +7,9 @@ import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Button
import androidx.navigation.findNavController
import androidx.navigation.fragment.findNavController
import kotlinx.android.synthetic.main.fragment_start.*
import kotlinx.android.synthetic.main.fragment_start.view.*
// TODO: Rename parameter arguments, choose names that match
// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
@@ -47,11 +46,11 @@ class StartFragment : Fragment() {
val inf = inflater.inflate(R.layout.fragment_start,container,false)
inf.button.setOnClickListener {
(inf.findViewById(R.id.button) as Button).setOnClickListener {
it.findNavController().navigate(StartFragmentDirections.actionStartFragmentToDestinationFragment1())
}
inf.button2.setOnClickListener {
(inf.findViewById(R.id.button2) as Button).setOnClickListener {
it.findNavController().navigate(StartFragmentDirections.actionStartFragmentToDestinationFragment2())
}
@@ -1,6 +1,5 @@
apply plugin: 'com.android.application'
apply plugin: 'kotlin-multiplatform'
apply plugin: 'kotlin-android-extensions'
group 'com.example'
version '1.0'