--target native-lib 不是目录 [英] --target native-lib is not a directory

查看:25
本文介绍了--target native-lib 不是目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在android项目中成功实现了Native支持,但是在更改项目路径后(只需将项目放入子目录)构建应用程序时出错.

I successfully implement the Native support in the android project, but after changing the project path (Just place the project into sub directory) getting error while building the app.

"app/.externalNativeBuild/cmake/debug/x86 --target native-lib is not a directory" 

也无法清理和重建项目.项目以前工作得很好.项目路径中也没有空格.

Also unable to clean and rebuild the project. Project is working prefect before. Also there is no space in the project path.

提前感谢您的支持.

我使用的是 Ubuntu 18.04、CMake 3.10.2、Android Studio 3.3

I am using Ubuntu 18.04, CMake 3.10.2, Android studio 3.3

这里是 CMakeLists.txt(路径:appModule/CMakeLists.txt)

Here is the CMakeLists.txt (path: appModule/CMakeLists.txt)

cmake_minimum_required(VERSION 3.4.1)

add_library( native-lib
         SHARED
         src/main/cpp/native-lib.cpp )

find_library( log-lib
          log )

target_link_libraries( native-lib
               ${log-lib} )

和 App build.gradele

and the App build.gradele

apply plugin: 'com.android.application'
apply plugin: 'io.fabric'

repositories {
    maven { url 'https://maven.fabric.io/public' }
    mavenCentral()
    google()
}

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId 'application_id'
        minSdkVersion 17
        targetSdkVersion 28
        versionCode 6
        versionName "1.2"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

        multiDexEnabled true
        externalNativeBuild {
      cmake {
          cppFlags "-std=c++11"
      }
        }
    }
    buildTypes {
        release {
      shrinkResources true
      minifyEnabled true
      proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
        debug {
      debuggable true
      shrinkResources true
      minifyEnabled true
      proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    externalNativeBuild {
        cmake {
      path "CMakeLists.txt"
        }
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

推荐答案

如果你改变了app --> appModule,你可能会尝试

If you changed app --> appModule, you might try to

  • 从 AS 关闭项目
  • 用 AS 重新打开
  • build > 刷新链接的 C++ 项目(这将强制"C++ 构建端清理东西)

Studio 3.3.0 有一个错误影响 IDE 行为,请使用版本 3.3.1更好

Studio 3.3.0 has a bug affecting IDE behavior, please use version 3.3.1 or better

对于 Gradle 的 CMake 支持,应用程序可以通过 3 种方式使用它,从最明确的方式开始到默认":

For Gradle's CMake support, application could use it in 3 ways, starting with most explicit way to "the default":

假设 Vanilla CMake 是从 CMake.org 本地下载的,配置 Gradle 使用

Assuming Vanilla CMake is downloaded locally from CMake.org, config Gradle with

  • 通知 gradle cmake 目录在哪里,在 local.properties 中,例如:cmake.dir=/your/vanilla/cmake/dir/like/linux-3.14.0
  • 将 cmake 版本传递给您的 app/build.gradle 文件中的 gradle,例如
  • inform gradle where cmake directory is, in local.properties, like: cmake.dir=/your/vanilla/cmake/dir/like/linux-3.14.0
  • pass cmake version to gradle in your app/build.gradle file, like
    android {
        externalNativeBuild {
            version "3.14.0-rc2"
            path '....'  // point to your CMakeLists.txt, relative path to
                         // THIS app/build.gradle file.
        }
    }

Vanilla CMake 的缺点可能是 SDK 中的模块(例如 AndroidNdkModules.cmake )可能不在您的模块路径中:该项目未使用 SDK/Studio 内部打包的 CMake.

The down side with Vanilla CMake might be that modules inside SDK ( like AndroidNdkModules.cmake ) may not be in your module path: the project is not using SDK/Studio internally packed CMake.

截至目前,SDK 提供了 2 个 cmake 版本:3.6.0-rc2 和 3.10.2.您的 sdk 管理器会将它们下载到内部已知目录 (sdk/cmake).项目可以选择一个特定的来使用.当然,您可以使用上述Vanilla CMake"方式,即应用程序配置所有内容——将 cmake.dir 指向您的 $SDK 的 cmake 路径(一直到但不包括 'bin/cmake').
您也可以忽略 cmake.dir 配置(Studio 提供了这种便利,因为它在 sdk 内部并由 sdk manager 下载),因此您只需要在 'app/build.gradle' 中配置 cmake 版本

As of now, SDK ships 2 cmake builds: 3.6.0-rc2 and 3.10.2. Your sdk manager would download them into the internal known directory (sdk/cmake). Project could pick up a specific one to use. Certainly you could use the above "Vanilla CMake" way, ie., application configures everything -- points cmake.dir to your $SDK's cmake path ( all the way up to, but no including, 'bin/cmake').
You could also ignore the cmake.dir configuration (Studio provides this convenience as it is inside sdk and downloaded by sdk manager), so you only need to configure cmake version in 'app/build.gradle'

    android {
        externalNativeBuild {
            version "3.10.2"
            path '....'
        }
    }

2个cmake版本在gradle插件功能方面没有区别,区别在于2个版本之间cmake本身的功能.

There is no difference between the 2 cmake versions concerning gradle plugin functionality, the difference is inside cmake itself's functionality between the 2 versions.

目前 gradle 插件的默认 cmake 选择是内部 3.6.0-rc2 版本.因此,如果您不配置 'cmake.dir' AND 'version',则默认值在起作用.您当然仍然可以使用Vanilla CMake"方式对其进行配置:cmake path and version;这有点可怕,但有一个小好处:当 Studio/Gradle 将 cmake 默认更改为 3.10.2 或其他时,您的应用程序不受影响.我们鼓励应用程序使用最新版本.作为应用程序开发人员,我可能还希望我的应用程序具有固定的行为,而不管构建工具的版本如何;从这个意义上说,显式方式会有所帮助.

Currently gradle plugin's default cmake pick is the internal 3.6.0-rc2 version. So if you do not configure 'cmake.dir' AND 'version', the default is in action. You certainly could still configure it as with "Vanilla CMake" way: cmake path and version; it is dreading a little bit, but there is a minor benefit: when Studio/Gradle changes cmake default to 3.10.2 or others, you app is not affected. We do encourage application to use the latest releases. As an application developer, I might also like my app to have a fixed behavior regardless of the versions of building tools; in that sense, explicit way helps.

  • CMake 版本:您可以运行cmake --version"来获取正确的版本号来配置 build.grale,它不是嵌入在sdk 的 cmake 目录.
  • 您的顶级 CMakeLists.txt 位置:对 gradle 插件无动于衷.实际上,您可能会将其与您的 C++ 代码放在一起,因此当您与其他平台共享时,它们(c++ 构建脚本和源代码)都在一个目录中.
  • CMake version: you would run 'cmake --version' to get the right version number to configure build.grale, it is NOT the full number embedded inside the sdk's cmake directory.
  • your top-level CMakeLists.txt location: indifference to gradle plugin. Practically you might put it together with your C++ code, so when you share with other platforms, they(c++ build script and source code) are inside one directory.

这篇关于--target native-lib 不是目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆