当前位置:网站首页>Error:Execution failed for task ':app:buildNative'. & gt; A problem occurred'x/x/x/'NDK build' error resolution

Error:Execution failed for task ':app:buildNative'. & gt; A problem occurred'x/x/x/'NDK build' error resolution

2022-06-11 05:37:00 Cockroach bully BBQ

The background of the story is like this   The function of the project to scan the license plate number , I found one on the Internet demo( There are N Much of the .so and ram、x86、.h 、.cpp、.mk And so on ), Import android studio This error is reported when running ,  Then go and see yourself ndk route    That's right! , And then over the wall googole After reading the relevant 66 Bar result   It's still useless .

Finally, I had no choice but to see Local my ndk-build This thing , Two files with similar names were found ,  One is

ndk-build.cmd
The other is
ndk-build

and Stack Overflow There is a very good answer on it   as follows :

It seems to distinguish , If it is windows The system will use tape .cmd Suffixed files run ( Don't android studio Can't you distinguish yourself ? doubt ....);

Finally, I put my own project build.gradle The file is changed to this    as follows :

task buildNative(type: Exec, description: 'Compile JNI source via NDK') {
    def ndkDir = android.ndkDirectory
    if (Os.isFamily(Os.FAMILY_WINDOWS)) {
        commandLine "$ndkDir/ndk-build.cmd",
                '-C', file('src/main/jni').absolutePath, // Change src/main/jni the relative path to your jni source
                '-j', Runtime.runtime.availableProcessors(),
                'all',
                'NDK_DEBUG=0'
    } else {
        commandLine "$ndkDir/ndk-build",
                '-C', file('src/main/jni').absolutePath, // Change src/main/jni the relative path to your jni source
                '-j', Runtime.runtime.availableProcessors(),
                'all',
                'NDK_DEBUG=0'
    }

}
Pay attention to is if Inside Os You need to import a class :
import org.apache.tools.ant.taskdefs.condition.Os
This is written in build.gradle Just the first few lines of the file ...



And then   compile 、 function    2 Minutes later   ok   No more mistakes    Problem solving !

原网站

版权声明
本文为[Cockroach bully BBQ]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/03/202203020538031191.html