1.问题:Caused by: java.lang.RuntimeException: Error while processing G:\studykl\app\src\main\res\drawable\ic_baseline_cloud_download_24.xml : Can’t process attribute android:fillColor="@android:color/white": references to other resources are not supported by build-time PNG generation—@android:color/white本来就是引用sdk的东西 解决:在app目录下的build.gradle中的defaultConfig {}添加 vectorDrawables.useSupportLibrary = true 如: defaultConfig { applicationId “com.th.studykl” minSdkVersion 14 targetSdkVersion 29 versionCode 1 versionName “1.0” vectorDrawables.useSupportLibrary = true testInstrumentationRunner “androidx.test.runner.AndroidJUnitRunner” } 2.问题:java.lang.RuntimeException: Manifest merger failed with multiple errors, see logs 解答:因为app中有modules,两个manifest文件的sdk编译版本不一样。改成一样的就解决了 3.导入第三aar包遇到ERROR: Failed to resolve: :aar名字: Affected Modules: app 解决:在project目录的build.gradle文件的allprojects {}里的repositories加入flatDir { dirs ‘libs’ } 整体 如:allprojects { repositories { google() jcenter() flatDir { dirs ‘libs’ }
}}
4.遇到IDE提示lateinit modifier is not allowed on properties of primitive types 解答:kotlin语言以解决null问题为主要目的的开发语言,java常见先声明成员变量,到用的时候再初始化,这点在kotlin直接这么写是不行的,因此有了lateinit的关键字,这个关键为它所修饰的成员变量赋值null初始化,对于基本类型如int类型使用lateinit修饰就会提示,解决办法就是直接初始化赋值。或者先用string代替,到用的时候再转换成int类型。 如果成员变量在构造方法中初始化这个关键词就可以不用使用了。 5.遇到IDE提示constructors are not allowed for objects 解答:object没有主构造,自然也不能出现次构造,这个区分了java静态类还有构造方法,kt是决不允许这样写,如果一定要这么写,格式是写一个普通kt类有构造方法,而类里面所有的成员变量和静态方法都用 companion object { 写 静态函数 } 包裹。这样就等同java静态类加构造方法了
6.java 中的byte[] buffer = new byte[size],到kotlin中怎么写 解答:val buffer = ByteArray(size)
7.Java中InputStream 一般成员变量名都习惯用is,kotlin中is是啥 解答:is在kt中是关键词等同java中的instanceof,如果一定要用需要使用is,这里延伸一下java中instanceof后一般是强转如 A a = (A)b,这个强转在kt中是这样实现b as A,翻译就是把b当做A。
8.res\values-v28\values-v28.xml:5:5-8:13: AAPT: error: resource android:attr/dialogCornerRadius not found 解决:
// 在app目录的build.gradle android中加入下面代码dependencies 里要对上 configurations.all { resolutionStrategy { force "com.android.support:appcompat-v7:27.1.1" force "com.android.support:support-v4:27.1.1" } } dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) implementation 'com.android.support:appcompat-v7:27.1.1' implementation 'com.android.support:support-v4:27.1.1' implementation "com.android.support:design:27.1.0" testImplementation 'junit:junit:4.12' androidTestImplementation 'com.android.support.test:runner:1.0.1' androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1' implementation project(':lib') }9.kotlin里面引用v7包的东西,却提示Unresolved reference: v7 解答:主要是androidx,把android.useAndroidX=false android.enableJetifier=false,然后所有引用androidx的都替换成v4或v7的
10.Cannot access built-in declaration ‘kotlin.Unit’. Ensure that you have a dependency on the Kotlin standard library 解答:我的是
// An highlighted block fun skinSelect(view:View){ this.startActivity(Intent( MainActivity@this, SkinActivity::class.java )) } SkinActivity::class.java的中.java爆红,类里面有提示config点击就行11.运行虚拟机提示“the emulator process for avd pixel_2_API_27 WAS killed” 解答:
