Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
433 views
in Technique[技术] by (71.8m points)

android - --target native-lib is not a directory

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.

Thanks for you support in advance.

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

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

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
    }
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

  • close the project from AS
  • re-open it with AS
  • build > Refresh Linked C++ Project ( this would "force" C++ build side to clean things )

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

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

Vanilla CMake

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

  • 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.
        }
    }

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.

Explicitly pick up SDK's 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 '....'
        }
    }

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.

Use Default: Let the Studio decide cmake version

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.

Additional Notes

  • 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.

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...