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

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

问题描述

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

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

和应用程序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":

假设香草CMake是从CMake.org本地下载的,则将Gradle配置为

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

  • local.properties中通知gradle cmake目录所在的位置,例如:cmake.dir=/your/vanilla/cmake/dir/like/linux-3.14.0
  • 将cmake版本传递到您的app/build.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管理器下载),因此您只需要在'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 '....'
        }
    }

关于gradle插件功能,这2个cmake版本之间没有区别,而这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"和版本",则默认为有效.当然,您仍然可以将其配置为"Vanilla CMake"方式:cmake路径和版本;它有点令人恐惧,但有一个较小的好处:当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天全站免登陆