将项目导入 Android Studio 后出错

Error after importing project to Android Studio

本文关键字:出错 Studio Android 项目 导入      更新时间:2023-10-16

我收到了一个旧代码,编码于2014年,我被要求更新一些功能。

我在运行代码时遇到问题,因为它是在 Eclipse 上构建的,现在我将其导入到 Android Studio 中。

首先,代码调用了项目中包含的 3 个库,其中一个在 cpp 中。这就是为什么我认为需要添加捆绑 ndk。

我添加了:android.useDeprecatedNdk=true to gradle-wrapper.properties

这些是我目前拥有的 gradle 文件:

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.0'
}
}
allprojects {
repositories {
jcenter()
}
}

第一图书馆格拉德尔

apply plugin: 'com.android.library'

android {
compileSdkVersion 16
buildToolsVersion "23.0.3"
defaultConfig {
minSdkVersion 5
targetSdkVersion 16
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}

第二图书馆

apply plugin: 'com.android.library'
android {
compileSdkVersion 16
buildToolsVersion "23.0.3"
defaultConfig {
minSdkVersion 5
targetSdkVersion 5
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile project(':FirstLibrary')
compile 'com.android.support:support-v4:18.0.0'
compile files('libs/libGoogleAnalyticsV2.jar')
}

第三图书馆

apply plugin: 'com.android.library'
android {
compileSdkVersion 16
buildToolsVersion "23.0.3"
defaultConfig {
minSdkVersion 5
targetSdkVersion 7
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile 'com.android.support:support-v4:18.0.0'
}

项目模块分级

apply plugin: 'com.android.application'
android {
compileSdkVersion 8
buildToolsVersion "23.0.3"
defaultConfig {
applicationId "com.application.id"
minSdkVersion 8
targetSdkVersion 17
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-project.txt'
}
}
}
dependencies {
compile project(':secondLbrary')
compile project(':thirdLibrary')
}

收到的最新错误:

错误:任务":库:编译调试NDK"执行失败。

错误:您的项目包含C++文件,但它未使用受支持的本机生成系统。 考虑将CMake或ndk-build与稳定的Android Gradle插件集成: https://developer.android.com/studio/projects/add-native-code.html 或使用实验插件: http://tools.android.com/tech-docs/new-build-system/gradle-experimental。

我该怎么做才能对此进行调查?

这通常与 gradle 版本有关 - 您应该更新到最新版本并重试。看这里插件太旧了。

另外 - 为什么需要"com.android.tools.build:gradle-experimental:0.7.0-alpha4"?

要在 Android Studio 中编译 cpp 代码:

  1. 您需要在Android SDK Manager上下载CMAKE,LLDB和NDK。

  2. 您需要制作CMakeList.txt并且需要放置用于编译CPP文件的脚本。

  3. 您需要在build.gradle中放置以下行:

    externalNativeBuild {
    cmake {
    path "CMakeLists.txt"
    }
    }