【问题标题】:Error after importing project to Android Studio将项目导入 Android Studio 后出错
【发布时间】:2017-12-07 15:17:09
【问题描述】:

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

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

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

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

这些是我目前拥有的 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()
    }
}

第一个库 Gradle

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'
}

项目的模块Gradle

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')
}

收到的最新错误:

错误:任务“:library:compileDebugNdk”执行失败。

错误:您的项目包含 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.

我能做些什么来调查这个?

【问题讨论】:

    标签: c++ android-studio gradle android-ndk


    【解决方案1】:

    这通常与 gradle 版本有关 - 您应该更新到最新版本并重试。看这里Plugin is too old

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

    【讨论】:

    • 感谢您的帮助,最初在我构建项目时,它给了我以下错误:错误:当前插件中不推荐使用 NDK 集成。经过一些研究,我了解到我需要使用 gradle experimental,因为如前所述,其中一个库位于 cpp 中。
    • 你应该考虑迁移到稳定版:tools.android.com/tech-docs/new-build-system/…
    • 我已经按照建议的链接,不幸的是我仍然面临这个错误:NDK 集成在当前插件中已弃用。将更新问题以包含所做的更改
    • 您使用的是哪个 Android Studio 版本?
    • 2.1.1,我要更新它吗?问题会解决吗?
    【解决方案2】:

    用于在 Android Studio 中编译 cpp 代码:

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

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

    3. 您需要在 build.gradle 中添加以下几行:

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

    【讨论】:

    • 我也有同样的问题,我用这个答案解决了。谢谢
    • 感谢您的贡献,我正在使用 ndk-build,因为我一直在阅读您使用 NDK 或 CMake。
    • 我下载了 LLDB 和 NDK,并在 local.properties 中设置了 ndk-build 的位置,并在 gradle-wrapper.properties 中设置了 android.useDeprecatedNdk=true。
    猜你喜欢
    • 1970-01-01
    • 2015-05-13
    • 2015-05-21
    • 1970-01-01
    • 1970-01-01
    • 2016-02-22
    • 2023-03-03
    • 1970-01-01
    相关资源
    最近更新 更多