我在 Android Studio 中遇到了两个主要问题。首先,我无法执行复制粘贴和剪切粘贴(ctrl+c - ctrl+v - ctrl+x)某些类(class)中的能力。为了解决这个问题,我单击“无效缓存/重新启动”,但它立即再次崩溃。
第二个问题是(我认为它与第一个问题相关)编译器无法识别已经定义的方法和属性。自动建议等不起作用。
我尝试解决该问题所采取的步骤是:
- 文件 -> 无效缓存/重新启动,
- 文件 -> 省电模式 -> 禁用,
- 关闭所有打开的标签页并重新启动,
- 文件 -> 将项目与 Gradle 文件同步,
- 文件 -> 与文件系统同步,
- 删除 JDK 并重新安装,
- 删除 Android Studio 并重新安装,
- 删除已下载的 SDK 文件和“.Android”文件夹,
- 禁用并删除所有插件。
- 在文件 -> 设置 -> 键盘映射中检查复制粘贴键盘映射
- 将项目从 bitbucket 拉到不同的 2 台计算机
- 创建新项目,使用 NotePad++ 将整个项目类复制到 新项目
- 尝试将所有 Java 代码转换为 Kotlin,无法转换
这是我的系统规范; Windows 10 家庭单语言 (TR),版本 1909。16 GB 内存。 Android Studio 3.5.3 和 Gradle 版本 3.5.3
我已经阅读了所有关于相同问题的帖子,但没有运气(这些帖子仅涉及 MAC 和 Linux 平台)。
更新 1.0 -> 我发现有些类不能执行上述操作,但有些类可以。
我意识到,不存在不能执行我上面描述的操作的类的图标。 (有时会神奇地出现“J”图标,当我单击另一个类时,这个 J 图标立即消失。)我认为 Android Studio 的 gradle 或文件系统无法将这些文件识别为类。
更新 2.0 -> 我注意到,当我单击 DuoFragment 的 Structure 部分(其中有 500 多行代码和未编译的类之一)时,无法加载任何内容。 DuoFragment 大小是否较大,难以处理?
另外,当我检查“构建”部分时,某些进程无法运行(我不知道这是否正常);
- 任务:app:compileDebugAidl 无源,
- 任务:app:compileDebugRenderscript 无源,
- 任务:app:processDebugJavaRes NO-SOURCE
更新3.0 ->
这是我的 Gradle 文件。 项目级别 Gradle 文件:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
maven { url 'https://jitpack.io' }
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
应用程序级 Gradle 文件。
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 29
buildToolsVersion "29.0.2"
defaultConfig {
applicationId "com.lotusif.dump2"
minSdkVersion 21
targetSdkVersion 29
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility = 1.8
targetCompatibility = 1.8
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.recyclerview:recyclerview:1.1.0'
implementation 'androidx.core:core:1.1.0'
// material widgets
implementation 'com.google.android.material:material:1.2.0-alpha03'
// progress bar with text
implementation "com.github.skydoves:progressview:1.0.3"
// sequence progress
implementation 'com.github.transferwise:sequence-layout:1.0.11'
// flash bar
implementation 'com.andrognito.flashbar:flashbar:1.0.2'
// toggle - switch button
implementation 'com.github.GwonHyeok:StickySwitch:0.0.15'
// Custom Toast message
implementation 'com.github.GrenderG:Toasty:1.4.2'
// liquid effect bar
implementation 'com.mikhaellopez:circularfillableloaders:1.3.2'
// bubble tab bar
implementation 'com.fxn769:bubbletabbar:1.0.3'
//glide image library
implementation 'com.github.bumptech.glide:glide:4.10.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.10.0'
// scaling layout
implementation 'com.github.iammert:ScalingLayout:1.2.1'
// lottie animation
implementation 'com.airbnb.android:lottie:3.3.1'
//Gson
implementation 'com.google.code.gson:gson:2.8.6'
//RxJava
implementation 'io.reactivex.rxjava2:rxjava:2.2.15'
implementation 'io.reactivex.rxjava2:rxandroid:2.0.1'
implementation 'com.daimajia.easing:library:2.1@aar'
implementation 'com.daimajia.androidanimations:library:2.3@aar'
//retrofit
implementation 'com.squareup.retrofit2:converter-gson:2.7.1'
implementation 'com.squareup.retrofit2:retrofit:2.7.1'
implementation 'com.squareup.retrofit2:adapter-rxjava2:2.7.1'
}
更新 1.0 图片
更新2.0图像
最佳答案
更新 -->Windows 10 单语言土耳其语的 Kotlin 库中存在错误。 (也许其他一些单语言 Windows 发行版也有同样的问题,我还不知道。)Kotlin 的一些库无法在土耳其操作系统上运行。我通过安装Windows 10 Pro English解决了这个问题。
使用 Windows 10 单语言土耳其语的其他开发人员从不同的角度面临着同样的问题。 ( Example1 和 Example2 )
旧答案
TL;DR -> 问题与使用 Kotlin 编写的第三方库有关。我已将 Java 项目转换为 Kotlin,所有有问题的第三方库都运行良好。 问题是关于 Java - Kotlin 冲突。
我想分享一下我是如何解决这个问题的,供以后遇到此类问题的人使用。
我一一完成了上面提到的所有步骤,但找不到任何解决方案,因此我决定检查我的第三方库。
首先,我禁用了所有第三方库,并查看了无法识别已定义方法和属性的类的状态。在禁用第三方库并进行 Rebuild Project 和 Sync Gradle 后,那些损坏的类的自动建议功能再次开始工作。然后,发现哪些第三方库有问题,我一一激活了这些第三方库。我发现哪些第三方库破坏了我的项目。
有 4 个第三方库破坏了我的项目:StickySwitch , ProgressView , SequenceLayout和 Flashbar 。当我删除这些库时,一切正常。删除库后,我的 Gradle 文件如下。
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 29
buildToolsVersion "29.0.2"
defaultConfig {
applicationId "com.lotusif.dump2"
minSdkVersion 21
targetSdkVersion 29
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility = 1.8
targetCompatibility = 1.8
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.recyclerview:recyclerview:1.1.0'
implementation 'androidx.core:core:1.1.0'
// material widgets
implementation 'com.google.android.material:material:1.2.0-alpha03'
// progress bar with text BUGGY!
// implementation "com.github.skydoves:progressview:1.0.3"
// sequence progress BUGGY !
// implementation 'com.github.transferwise:sequence-layout:1.0.11'
// flash bar BUGGY !
// implementation 'com.andrognito.flashbar:flashbar:1.0.2'
// toggle - switch button BUGGY !
// implementation 'com.github.GwonHyeok:StickySwitch:0.0.15'
// Custom Toast message
implementation 'com.github.GrenderG:Toasty:1.4.2'
// liquid effect bar
implementation 'com.mikhaellopez:circularfillableloaders:1.3.2'
// bubble tab bar
implementation 'com.fxn769:bubbletabbar:1.0.3'
// android chart library
implementation 'com.github.PhilJay:MPAndroidChart:v3.1.0'
//glide image library
implementation 'com.github.bumptech.glide:glide:4.10.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.10.0'
// scaling layout
implementation 'com.github.iammert:ScalingLayout:1.2.1'
// lottie animation
implementation 'com.airbnb.android:lottie:3.3.1'
//Gson
implementation 'com.google.code.gson:gson:2.8.6'
//RxJava
implementation 'io.reactivex.rxjava2:rxjava:2.2.15'
implementation 'io.reactivex.rxjava2:rxandroid:2.0.1'
implementation 'com.daimajia.easing:library:2.1@aar'
implementation 'com.daimajia.androidanimations:library:2.3@aar'
//retrofit
implementation 'com.squareup.retrofit2:converter-gson:2.7.1'
implementation 'com.squareup.retrofit2:retrofit:2.7.1'
implementation 'com.squareup.retrofit2:adapter-rxjava2:2.7.1'
}
那么,那些破坏我的项目的库的共同特征是什么?我的项目是用 Java 编写的,但库是用 Kotlin 编写的。等一下,我不能在我的 Java 项目中使用 Kotlin 库吗? Yes, I can 。我必须在我的 gradle.properties 中添加 android.useAndroidX=true
和 android.enableJetifier=true
,就是这样。但是,如果我已经在我的 gradle.properties 中添加了这些行,但它不起作用怎么办?
# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
org.gradle.jvmargs=-Xmx1536m
# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
# AndroidX package structure to make it clearer which packages are bundled with the
# Android operating system, and which are packaged with your app's APK
# https://developer.android.com/topic/libraries/support-library/androidx-rn
android.useAndroidX=true
# Automatically convert third-party libraries to use AndroidX
android.enableJetifier=true
我不明白为什么 kotlin 库不能与我的 Java 项目一起使用。正如您在我的 Gradle 文件中看到的,我正在使用 apply plugin: 'kotlin-android'
和 apply plugin: 'kotlin-android-extensions'
用于 Kotlin 支持。
我如何拯救我的项目?据我所知,有两个可用的选项。第一种方法是删除这 4 个第三方库并且无法使用它们,第二种方法是将所有 Java 类转换为 Kotlin 类(我之前尝试过,但直到禁用所有第三方库才起作用)。我选择将所有 Java 类转换为 Kotlin 类。因此,我能够使用上面提到的 4 个第三方库。
我花了30天才解决这个问题。现在,我正在研究 Kotlin 语言。结果,我的项目运行没有任何问题。
关于android - 无法在 Android Studio 中执行复制粘贴,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59512559/