diff options
author | Yabin Cui <yabinc@google.com> | 2017-06-27 21:28:31 +0000 |
---|---|---|
committer | android-build-merger <android-build-merger@google.com> | 2017-06-27 21:28:31 +0000 |
commit | 1e391c4bad6766e7c928ea51082b471014d2f1b9 (patch) | |
tree | 3a7ae9c432c70abec88418aa8dd9e34bc09db619 /simpleperf/demo/SimpleperfExampleOfKotlin/app | |
parent | 0d864d37048368a46eb5e244a6b6ecabde26679e (diff) | |
parent | d39db9b0f5b39815b33cf56401c18f07332c304f (diff) | |
download | extras-1e391c4bad6766e7c928ea51082b471014d2f1b9.tar.gz |
Merge "simpleperf: add demo for kotlin."
am: d39db9b0f5
Change-Id: Ie469016cf1d336ac2c88a0522c7913aee8d26ec1
Diffstat (limited to 'simpleperf/demo/SimpleperfExampleOfKotlin/app')
29 files changed, 266 insertions, 0 deletions
diff --git a/simpleperf/demo/SimpleperfExampleOfKotlin/app/.gitignore b/simpleperf/demo/SimpleperfExampleOfKotlin/app/.gitignore new file mode 100644 index 00000000..796b96d1 --- /dev/null +++ b/simpleperf/demo/SimpleperfExampleOfKotlin/app/.gitignore @@ -0,0 +1 @@ +/build diff --git a/simpleperf/demo/SimpleperfExampleOfKotlin/app/build.gradle b/simpleperf/demo/SimpleperfExampleOfKotlin/app/build.gradle new file mode 100644 index 00000000..e7110fb7 --- /dev/null +++ b/simpleperf/demo/SimpleperfExampleOfKotlin/app/build.gradle @@ -0,0 +1,37 @@ +apply plugin: 'com.android.application' + +apply plugin: 'kotlin-android' + +apply plugin: 'kotlin-android-extensions' + +apply from: 'profiling.gradle' + +android { + compileSdkVersion 25 + buildToolsVersion "26.0.0" + defaultConfig { + applicationId "com.example.simpleperf.simpleperfexampleofkotlin" + minSdkVersion 15 + targetSdkVersion 26 + versionCode 1 + versionName "1.0" + testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" + } + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + } + } +} + +dependencies { + implementation fileTree(dir: 'libs', include: ['*.jar']) + androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', { + exclude group: 'com.android.support', module: 'support-annotations' + }) + implementation"org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version" + implementation 'com.android.support:appcompat-v7:25.4.0' + testImplementation 'junit:junit:4.12' + implementation 'com.android.support.constraint:constraint-layout:1.0.2' +} diff --git a/simpleperf/demo/SimpleperfExampleOfKotlin/app/profiling.gradle b/simpleperf/demo/SimpleperfExampleOfKotlin/app/profiling.gradle new file mode 100644 index 00000000..661d5497 --- /dev/null +++ b/simpleperf/demo/SimpleperfExampleOfKotlin/app/profiling.gradle @@ -0,0 +1,60 @@ + +// Set when building only part of the abis in the apk. +def abiFiltersForWrapScript = [] + +android { + buildTypes { + profiling { + initWith debug + externalNativeBuild { + cmake { + // cmake Debug build type uses -O0, which makes the code slow. + arguments "-DCMAKE_BUILD_TYPE=Release" + } + } + packagingOptions { + // Contain debug info in the libraries. + doNotStrip "**.so" + + // Exclude wrap.sh for architectures not built. + if (abiFiltersForWrapScript) { + def exclude_abis = ["armeabi", "armeabi-v7a", "arm64-v8a", + "x86", "x86_64", "mips", "mips64"] + .findAll{ !(it in abiFiltersForWrapScript) } + .collect{ "**/" + it + "/wrap.sh" } + excludes += exclude_abis + } + } + + // Add lib/xxx/wrap.sh in the apk. This is to enable java profiling on Android O + // devices. + sourceSets { + main { + resources { + srcDir { + "profiling_apk_add_dir" + } + } + } + } + } + } +} + +def writeWrapScriptToFullyCompileJavaApp(wrapFile) { + wrapFile.withWriter { writer -> + writer.write('#!/system/bin/sh\n') + writer.write('\$@\n') + } +} + +task createProfilingApkAddDir { + for (String abi : ["armeabi", "armeabi-v7a", "arm64-v8a", "x86", "x86_64", "mips", "mips64"]) { + def dir = new File("app/profiling_apk_add_dir/lib/" + abi) + dir.mkdirs() + def wrapFile = new File(dir, "wrap.sh") + writeWrapScriptToFullyCompileJavaApp(wrapFile) + println "write file " + wrapFile.path + } +} + diff --git a/simpleperf/demo/SimpleperfExampleOfKotlin/app/profiling_apk_add_dir/lib/arm64-v8a/wrap.sh b/simpleperf/demo/SimpleperfExampleOfKotlin/app/profiling_apk_add_dir/lib/arm64-v8a/wrap.sh new file mode 100644 index 00000000..047ea6fa --- /dev/null +++ b/simpleperf/demo/SimpleperfExampleOfKotlin/app/profiling_apk_add_dir/lib/arm64-v8a/wrap.sh @@ -0,0 +1,2 @@ +#!/system/bin/sh +$@ diff --git a/simpleperf/demo/SimpleperfExampleOfKotlin/app/profiling_apk_add_dir/lib/armeabi-v7a/wrap.sh b/simpleperf/demo/SimpleperfExampleOfKotlin/app/profiling_apk_add_dir/lib/armeabi-v7a/wrap.sh new file mode 100644 index 00000000..047ea6fa --- /dev/null +++ b/simpleperf/demo/SimpleperfExampleOfKotlin/app/profiling_apk_add_dir/lib/armeabi-v7a/wrap.sh @@ -0,0 +1,2 @@ +#!/system/bin/sh +$@ diff --git a/simpleperf/demo/SimpleperfExampleOfKotlin/app/profiling_apk_add_dir/lib/armeabi/wrap.sh b/simpleperf/demo/SimpleperfExampleOfKotlin/app/profiling_apk_add_dir/lib/armeabi/wrap.sh new file mode 100644 index 00000000..047ea6fa --- /dev/null +++ b/simpleperf/demo/SimpleperfExampleOfKotlin/app/profiling_apk_add_dir/lib/armeabi/wrap.sh @@ -0,0 +1,2 @@ +#!/system/bin/sh +$@ diff --git a/simpleperf/demo/SimpleperfExampleOfKotlin/app/profiling_apk_add_dir/lib/mips/wrap.sh b/simpleperf/demo/SimpleperfExampleOfKotlin/app/profiling_apk_add_dir/lib/mips/wrap.sh new file mode 100644 index 00000000..047ea6fa --- /dev/null +++ b/simpleperf/demo/SimpleperfExampleOfKotlin/app/profiling_apk_add_dir/lib/mips/wrap.sh @@ -0,0 +1,2 @@ +#!/system/bin/sh +$@ diff --git a/simpleperf/demo/SimpleperfExampleOfKotlin/app/profiling_apk_add_dir/lib/mips64/wrap.sh b/simpleperf/demo/SimpleperfExampleOfKotlin/app/profiling_apk_add_dir/lib/mips64/wrap.sh new file mode 100644 index 00000000..047ea6fa --- /dev/null +++ b/simpleperf/demo/SimpleperfExampleOfKotlin/app/profiling_apk_add_dir/lib/mips64/wrap.sh @@ -0,0 +1,2 @@ +#!/system/bin/sh +$@ diff --git a/simpleperf/demo/SimpleperfExampleOfKotlin/app/profiling_apk_add_dir/lib/x86/wrap.sh b/simpleperf/demo/SimpleperfExampleOfKotlin/app/profiling_apk_add_dir/lib/x86/wrap.sh new file mode 100644 index 00000000..047ea6fa --- /dev/null +++ b/simpleperf/demo/SimpleperfExampleOfKotlin/app/profiling_apk_add_dir/lib/x86/wrap.sh @@ -0,0 +1,2 @@ +#!/system/bin/sh +$@ diff --git a/simpleperf/demo/SimpleperfExampleOfKotlin/app/profiling_apk_add_dir/lib/x86_64/wrap.sh b/simpleperf/demo/SimpleperfExampleOfKotlin/app/profiling_apk_add_dir/lib/x86_64/wrap.sh new file mode 100644 index 00000000..047ea6fa --- /dev/null +++ b/simpleperf/demo/SimpleperfExampleOfKotlin/app/profiling_apk_add_dir/lib/x86_64/wrap.sh @@ -0,0 +1,2 @@ +#!/system/bin/sh +$@ diff --git a/simpleperf/demo/SimpleperfExampleOfKotlin/app/proguard-rules.pro b/simpleperf/demo/SimpleperfExampleOfKotlin/app/proguard-rules.pro new file mode 100644 index 00000000..bd138859 --- /dev/null +++ b/simpleperf/demo/SimpleperfExampleOfKotlin/app/proguard-rules.pro @@ -0,0 +1,25 @@ +# Add project specific ProGuard rules here. +# By default, the flags in this file are appended to flags specified +# in /usr/local/google/home/yabinc/Android/Sdk/tools/proguard/proguard-android.txt +# You can edit the include path and order by changing the proguardFiles +# directive in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# Add any project specific keep options here: + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile diff --git a/simpleperf/demo/SimpleperfExampleOfKotlin/app/src/androidTest/java/com/example/simpleperf/simpleperfexampleofkotlin/ExampleInstrumentedTest.kt b/simpleperf/demo/SimpleperfExampleOfKotlin/app/src/androidTest/java/com/example/simpleperf/simpleperfexampleofkotlin/ExampleInstrumentedTest.kt new file mode 100644 index 00000000..8946158e --- /dev/null +++ b/simpleperf/demo/SimpleperfExampleOfKotlin/app/src/androidTest/java/com/example/simpleperf/simpleperfexampleofkotlin/ExampleInstrumentedTest.kt @@ -0,0 +1,24 @@ +package com.example.simpleperf.simpleperfexampleofkotlin + +import android.support.test.InstrumentationRegistry +import android.support.test.runner.AndroidJUnit4 + +import org.junit.Test +import org.junit.runner.RunWith + +import org.junit.Assert.* + +/** + * Instrumented test, which will execute on an Android device. + * + * See [testing documentation](http://d.android.com/tools/testing). + */ +@RunWith(AndroidJUnit4::class) +class ExampleInstrumentedTest { + @Test + fun useAppContext() { + // Context of the app under test. + val appContext = InstrumentationRegistry.getTargetContext() + assertEquals("com.example.simpleperf.simpleperfexampleofkotlin", appContext.packageName) + } +} diff --git a/simpleperf/demo/SimpleperfExampleOfKotlin/app/src/main/AndroidManifest.xml b/simpleperf/demo/SimpleperfExampleOfKotlin/app/src/main/AndroidManifest.xml new file mode 100644 index 00000000..05eb9ee4 --- /dev/null +++ b/simpleperf/demo/SimpleperfExampleOfKotlin/app/src/main/AndroidManifest.xml @@ -0,0 +1,21 @@ +<?xml version="1.0" encoding="utf-8"?> +<manifest xmlns:android="http://schemas.android.com/apk/res/android" + package="com.example.simpleperf.simpleperfexampleofkotlin"> + + <application + android:allowBackup="true" + android:icon="@mipmap/ic_launcher" + android:label="@string/app_name" + android:roundIcon="@mipmap/ic_launcher_round" + android:supportsRtl="true" + android:theme="@style/AppTheme"> + <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>
\ No newline at end of file diff --git a/simpleperf/demo/SimpleperfExampleOfKotlin/app/src/main/java/com/example/simpleperf/simpleperfexampleofkotlin/MainActivity.kt b/simpleperf/demo/SimpleperfExampleOfKotlin/app/src/main/java/com/example/simpleperf/simpleperfexampleofkotlin/MainActivity.kt new file mode 100644 index 00000000..55d47aa3 --- /dev/null +++ b/simpleperf/demo/SimpleperfExampleOfKotlin/app/src/main/java/com/example/simpleperf/simpleperfexampleofkotlin/MainActivity.kt @@ -0,0 +1,29 @@ +package com.example.simpleperf.simpleperfexampleofkotlin + +import android.support.v7.app.AppCompatActivity +import android.os.Bundle + +class MainActivity : AppCompatActivity() { + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.activity_main) + createBusyThread() + } + + fun createBusyThread() { + object : Thread() { + var i = 0 + + override fun run() { + while (true) { + i = callFunction(i) + } + } + + fun callFunction(i: Int): Int { + return i + 1 + } + }.start() + } +} diff --git a/simpleperf/demo/SimpleperfExampleOfKotlin/app/src/main/res/layout/activity_main.xml b/simpleperf/demo/SimpleperfExampleOfKotlin/app/src/main/res/layout/activity_main.xml new file mode 100644 index 00000000..4c7edcf2 --- /dev/null +++ b/simpleperf/demo/SimpleperfExampleOfKotlin/app/src/main/res/layout/activity_main.xml @@ -0,0 +1,18 @@ +<?xml version="1.0" encoding="utf-8"?> +<android.support.constraint.ConstraintLayout 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" + tools:context="com.example.simpleperf.simpleperfexampleofkotlin.MainActivity"> + + <TextView + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="Hello World!" + app:layout_constraintBottom_toBottomOf="parent" + app:layout_constraintLeft_toLeftOf="parent" + app:layout_constraintRight_toRightOf="parent" + app:layout_constraintTop_toTopOf="parent" /> + +</android.support.constraint.ConstraintLayout> diff --git a/simpleperf/demo/SimpleperfExampleOfKotlin/app/src/main/res/mipmap-hdpi/ic_launcher.png b/simpleperf/demo/SimpleperfExampleOfKotlin/app/src/main/res/mipmap-hdpi/ic_launcher.png Binary files differnew file mode 100644 index 00000000..55073031 --- /dev/null +++ b/simpleperf/demo/SimpleperfExampleOfKotlin/app/src/main/res/mipmap-hdpi/ic_launcher.png diff --git a/simpleperf/demo/SimpleperfExampleOfKotlin/app/src/main/res/mipmap-hdpi/ic_launcher_round.png b/simpleperf/demo/SimpleperfExampleOfKotlin/app/src/main/res/mipmap-hdpi/ic_launcher_round.png Binary files differnew file mode 100644 index 00000000..8fab6a3a --- /dev/null +++ b/simpleperf/demo/SimpleperfExampleOfKotlin/app/src/main/res/mipmap-hdpi/ic_launcher_round.png diff --git a/simpleperf/demo/SimpleperfExampleOfKotlin/app/src/main/res/mipmap-mdpi/ic_launcher.png b/simpleperf/demo/SimpleperfExampleOfKotlin/app/src/main/res/mipmap-mdpi/ic_launcher.png Binary files differnew file mode 100644 index 00000000..6bc7fcd6 --- /dev/null +++ b/simpleperf/demo/SimpleperfExampleOfKotlin/app/src/main/res/mipmap-mdpi/ic_launcher.png diff --git a/simpleperf/demo/SimpleperfExampleOfKotlin/app/src/main/res/mipmap-mdpi/ic_launcher_round.png b/simpleperf/demo/SimpleperfExampleOfKotlin/app/src/main/res/mipmap-mdpi/ic_launcher_round.png Binary files differnew file mode 100644 index 00000000..1eecc0e7 --- /dev/null +++ b/simpleperf/demo/SimpleperfExampleOfKotlin/app/src/main/res/mipmap-mdpi/ic_launcher_round.png diff --git a/simpleperf/demo/SimpleperfExampleOfKotlin/app/src/main/res/mipmap-xhdpi/ic_launcher.png b/simpleperf/demo/SimpleperfExampleOfKotlin/app/src/main/res/mipmap-xhdpi/ic_launcher.png Binary files differnew file mode 100644 index 00000000..ec87dceb --- /dev/null +++ b/simpleperf/demo/SimpleperfExampleOfKotlin/app/src/main/res/mipmap-xhdpi/ic_launcher.png diff --git a/simpleperf/demo/SimpleperfExampleOfKotlin/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png b/simpleperf/demo/SimpleperfExampleOfKotlin/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png Binary files differnew file mode 100644 index 00000000..05ca079c --- /dev/null +++ b/simpleperf/demo/SimpleperfExampleOfKotlin/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png diff --git a/simpleperf/demo/SimpleperfExampleOfKotlin/app/src/main/res/mipmap-xxhdpi/ic_launcher.png b/simpleperf/demo/SimpleperfExampleOfKotlin/app/src/main/res/mipmap-xxhdpi/ic_launcher.png Binary files differnew file mode 100644 index 00000000..6f67f21b --- /dev/null +++ b/simpleperf/demo/SimpleperfExampleOfKotlin/app/src/main/res/mipmap-xxhdpi/ic_launcher.png diff --git a/simpleperf/demo/SimpleperfExampleOfKotlin/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png b/simpleperf/demo/SimpleperfExampleOfKotlin/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png Binary files differnew file mode 100644 index 00000000..8bac0f27 --- /dev/null +++ b/simpleperf/demo/SimpleperfExampleOfKotlin/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png diff --git a/simpleperf/demo/SimpleperfExampleOfKotlin/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png b/simpleperf/demo/SimpleperfExampleOfKotlin/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png Binary files differnew file mode 100644 index 00000000..0327e13f --- /dev/null +++ b/simpleperf/demo/SimpleperfExampleOfKotlin/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png diff --git a/simpleperf/demo/SimpleperfExampleOfKotlin/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png b/simpleperf/demo/SimpleperfExampleOfKotlin/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png Binary files differnew file mode 100644 index 00000000..bacd3e75 --- /dev/null +++ b/simpleperf/demo/SimpleperfExampleOfKotlin/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png diff --git a/simpleperf/demo/SimpleperfExampleOfKotlin/app/src/main/res/values/colors.xml b/simpleperf/demo/SimpleperfExampleOfKotlin/app/src/main/res/values/colors.xml new file mode 100644 index 00000000..3ab3e9cb --- /dev/null +++ b/simpleperf/demo/SimpleperfExampleOfKotlin/app/src/main/res/values/colors.xml @@ -0,0 +1,6 @@ +<?xml version="1.0" encoding="utf-8"?> +<resources> + <color name="colorPrimary">#3F51B5</color> + <color name="colorPrimaryDark">#303F9F</color> + <color name="colorAccent">#FF4081</color> +</resources> diff --git a/simpleperf/demo/SimpleperfExampleOfKotlin/app/src/main/res/values/strings.xml b/simpleperf/demo/SimpleperfExampleOfKotlin/app/src/main/res/values/strings.xml new file mode 100644 index 00000000..7972edf9 --- /dev/null +++ b/simpleperf/demo/SimpleperfExampleOfKotlin/app/src/main/res/values/strings.xml @@ -0,0 +1,3 @@ +<resources> + <string name="app_name">SimpleperfExampleOfKotlin</string> +</resources> diff --git a/simpleperf/demo/SimpleperfExampleOfKotlin/app/src/main/res/values/styles.xml b/simpleperf/demo/SimpleperfExampleOfKotlin/app/src/main/res/values/styles.xml new file mode 100644 index 00000000..5885930d --- /dev/null +++ b/simpleperf/demo/SimpleperfExampleOfKotlin/app/src/main/res/values/styles.xml @@ -0,0 +1,11 @@ +<resources> + + <!-- Base application theme. --> + <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"> + <!-- Customize your theme here. --> + <item name="colorPrimary">@color/colorPrimary</item> + <item name="colorPrimaryDark">@color/colorPrimaryDark</item> + <item name="colorAccent">@color/colorAccent</item> + </style> + +</resources> diff --git a/simpleperf/demo/SimpleperfExampleOfKotlin/app/src/test/java/com/example/simpleperf/simpleperfexampleofkotlin/ExampleUnitTest.kt b/simpleperf/demo/SimpleperfExampleOfKotlin/app/src/test/java/com/example/simpleperf/simpleperfexampleofkotlin/ExampleUnitTest.kt new file mode 100644 index 00000000..39fbbf85 --- /dev/null +++ b/simpleperf/demo/SimpleperfExampleOfKotlin/app/src/test/java/com/example/simpleperf/simpleperfexampleofkotlin/ExampleUnitTest.kt @@ -0,0 +1,17 @@ +package com.example.simpleperf.simpleperfexampleofkotlin + +import org.junit.Test + +import org.junit.Assert.* + +/** + * Example local unit test, which will execute on the development machine (host). + * + * See [testing documentation](http://d.android.com/tools/testing). + */ +class ExampleUnitTest { + @Test + fun addition_isCorrect() { + assertEquals(4, 2 + 2) + } +} |