Android Studio 踩坑记录,持续更新

时间:2024-03-24 14:54:34


由于使用 Android Studio 也有些时候了,一路上踩的坑也很多,为了以后遇坑有个参考,特此记录一下目前为止的坑。

一、调试应用时报错:Could not connect to remote process. Aborting debug session.

症状

Could not connect to remote process. Aborting debug session.

解决办法

1、在 app Module 的 build.gradle 文件中加入:

...
android {
    ...
    buildTypes {
        release {
            ...
        }
        debug {
        	// 加入下面三行。
            debuggable true
            jniDebuggable true
            renderscriptDebuggable true
        }
    }
    ...
}
...

2、如果这个应用调试的时候不设置启动 Activity 的话会永远报上面的错误,解决方法:
(一)点击 app ,选择 Edit Configurations。
Android Studio 踩坑记录,持续更新
(二)在 Edit Configurations 窗口左边选择 app ,然后右边选择 General ,点击 Launch 右边的选择框选择 Default Activity
Android Studio 踩坑记录,持续更新
Android Studio 踩坑记录,持续更新
(三)点击右下角 OK 按钮。

二、Gradle Build 构建到 :app:preDebugAndroidTestBuild 时报错 Conflict with dependency ‘com.android.support:support-annotations’ in project ‘:app’. Resolved versions for app (26.1.0) and test app (27.1.1) differ. See https://d.android.com/r/tools/test-apk-dependency-conflicts.html for details.

症状

运行或调试应用程序构建到:app:preDebugAndroidTestBuild 这一步时报错:

Conflict with dependency 'com.android.support:support-annotations' in project ':app'. Resolved versions for app (26.1.0) and test app (27.1.1) differ. See https://d.android.com/r/tools/test-apk-dependency-conflicts.html for details.

解决办法

在 app Module 的 build.gradle 文件中加入:

...
android {
    ...
}
...
// 加入下面的内容。
configurations.all {
    resolutionStrategy.force 'com.android.support:support-annotations:27.1.1'
}
...
dependencies {
    ...
}
...

三、新建项目报 Gradle sync failed: No toolchains found in the NDK toolchains folder for ABI with prefix: mips64el-linux-android

症状

新建带 NDK 的项目时报错:

Gradle sync failed: No toolchains found in the NDK toolchains folder for ABI with prefix: mips64el-linux-android

解决办法

从 Android 官网重新下载一个最新版本 NDK ,点击下载
把下载下来的文件解压后,到 Android Studio 如下设置:
(一)点击左上角 File ,然后选择 Project Structure
Android Studio 踩坑记录,持续更新
(二)打开的窗口中左边选择 SDK Location ,把右边 Android NDK location 改成刚才解压的 NDK 路径。
Android Studio 踩坑记录,持续更新
(三)关闭窗口,等 Sync 结束后就不报错了。

持续更新中