はKotlinによって作られた非常にシンプルなアプリがあり、それは3.0なぜアプリはKotlinのAndroid 4.xで動作しないのですか?
Androidのメーカーにアンドロイド8.0、Androidの6.0とAndroid 5.1の下でうまく機能することができますが、私はエラーメッセージ「java.lang.RuntimeExceptionを取得:アクティビティをインスタンス化することができません。 ComponentInfo {info.dodata.mirror/ui.UIMain}:java.lang.ClassNotFoundException:ui.UIMain "Android 4.1でアプリケーションを実行すると、 2(これは本当の携帯電話である)とAndroid 4.2.2
あなたは
package ui
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import info.dodata.mirror.R
class UIMain : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.layout_main)
}
}
UIMain.kt https://www.dropbox.com/s/9f0yxp5pqqxtcxq/Mirror.zip?dl=0
でダウンロードでアプリを、それをテストすることができますAndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="info.dodata.mirror">
<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="ui.UIMain">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
build.gradle(モジュール:アプリ)のAndroid 5.0で
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 26
flavorDimensions "default"
defaultConfig {
// Enabling multidex support.
multiDexEnabled true
applicationId "info.dodata.mirror"
minSdkVersion 15
targetSdkVersion 26
versionCode 1
versionName "1.01"
archivesBaseName = "BackupSettings-V" + versionName
}
productFlavors {
free {
applicationId "info.dodata.mirror"
}
pro {
applicationId "info.dodata.mirror.pro"
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
buildConfigField "boolean", "IsDebugMode", "false"
}
debug {
buildConfigField "boolean", "IsDebugMode", "true"
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:multidex:1.0.2'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
implementation "org.jetbrains.anko:anko-commons:$anko_version"
implementation "org.jetbrains.anko:anko-sqlite:$anko_version"
}
build.gradle(トップ)
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.kotlin_version = '1.1.51'
ext.anko_version = '0.10.2'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
ありがとうございます!アンドロイド:name = "android.support.multidex.MultiDexApplication" – HelloCW
を追加した後、アプリがクラッシュするアプリはAndroid 4.0でうまく動作することができます。マルチディクスのtrueと実装 'com.android.support:multidex:1.0.2' – HelloCW
@HelloCWあなたのアプリのサイズが十分でなくても、multidexは必要ない場合は、それを削除してください。ビルド時間も速くなります。 – ephemient