Use Android Studo to develop NDK's gradle configuration (debug C code)

Source: Internet
Author: User
Tags addall return tag unsupported

Configuration:

The version number used is AS1.5 (you can also try a higher version number). Gradle address is Distributionurl=https\://services.gradle.org/distributions/gradle-2.8-all.zip

The NDK uses the CrystaX ndk .

A reference: HTTPS://GITHUB.COM/TSINSTUDIO/ANDROIDDEV/BLOB/MASTER/ANDROID%20NDK%20C%2B%2B%20 development tool: ANDROID%20STUDIO.MD


Problems:
1. When I switch between the NDK configuration of MK and the NDK configuration of Gradle, I suddenly cannot debug into C + + code. And then through
Empty the Main/jni/android.mk file,
Click Build->clean,
In the Debug interface right-click tab title (such as Ctbmanager Native)->close tab (Close all Debug tab) and then can debug into the
I don't know which step to fix the problem. If you encounter a successful compilation but cannot debug C + + files, try these steps. It is not recommended to switch between the MK and Gradle configurations at the same time.
2. Suppose the C file is an error. Consider the ability to change the C file, than to solve the error is simple

Gradle Code:
Import org.apache.tools.ant.taskdefs.condition.Osimport org.gradle.internal.os.operatingsystem;apply plugin: ' Com.android.model.application ' final app_abis = ["Armeabi", "armeabi-v7a", "arm64-v8a"]final boost_shared_libs = ["        Boost_serialization "," Boost_system "," Boost_filesystem "," Boost_thread "]model {android {compilesdkversion = 23 Buildtoolsversion = "23.0.2" defaultconfig.with {ApplicationID = "Com.duotin.ctblib" M  Insdkversion.apilevel = Targetsdkversion.apilevel = Compilesdkversion.astype (Integer) Versioncode = 1 Versionname = "1.0"}} android.ndk {toolchain = "gcc" toolchainversion = "4.9 "ModuleName =" Ctblib "Cppflags.add ("-std=c++11 ") Cppflags.add ("-fexceptions ") Cppflags.add (" -frtti ") Cppflags.add ("-I "+ getboostincdir ()) Cppflags.addall (["-fvisibility=hidden ","-wno-error=format-se Curity ","-i${file ("sRc/main/jni/jnisrc ")}". ToString (), "-i${file (" src/main/jni/src/jelly ")}". ToString (), "-i${file (" Src/main/jni/src/papaya ")}". ToString (), "-i${file (" Src/main/jni/src/helper ") } ". ToString (),"-i${file ("Src/main/jni/src/helper/utf8")} ". ToString (),"-I ${file ("Src/main/jni/src/ctbmodel")} ". ToString (),"-i${file ("Src/main/jni/src/ctbmodel/ctbalbum")}                         ". ToString (),"-i${file ("Src/main/jni/src/ctbmodel/ctbalbumparser")} ". ToString (), "-i${file (" Src/main/jni/src/ctbmodel/ctbbasemodel ")}". ToString (), "-i${file (" src/main/jni/                         Src/ctbmodel/ctbtrack ")}". ToString (), "-i${file (" Src/main/jni/src/xml ")}". ToString (), "-i${file (" Src/main/jni/src/xml/xmlmodel ")}". ToString (), "-i${file (" src/main/jni/src/x Ml/xmlmodel/xmlattrnode ")} ". ToString (),"-i${file ("Src/main/jni/src/xml/xmlmodel/xmlbasenode")} ". ToString (), "-i${file (" Src/main/jni/src/xml/xmlmodel/xmlelementnode ")}". ToString (), "-i${file (" src/ Main/jni/src/xml/xmlmodel/xmltextnode ")}". ToString (), "-i${file (" Src/main/jni/src/xml/xmlutil ")}".                         ToString (), "-i${file (" Src/main/jni/src/xml/xmlutil/boostxmlutil ")}". ToString (), "-i${file (" Src/main/jni/src/module ")}". ToString (), "-i${file (" Src/main/jni/src/ctbdatamanag                         Er ")}". ToString (), "-i${file (" Src/main/jni/src/sync/syncprocess ")}". ToString (), "-i${file (" Src/main/jni/src/sync/task ")}". ToString (), "-i${file (" Src/main/jni/src/synclog ")} ". ToString (),"-i${file ("Src/main/jni/src/utils")} ". ToString ()]) Cppflags.add ("-i${ File ("src/main/jni/neon/Include ")}". ToString ()) Cflags.addall (["-i${file (" Src/main/jni/jnisrc ")}". ToString (), "-i${fi                       Le ("src/main/jni/src/jelly")} ". ToString (),"-i${file ("Src/main/jni/src/papaya")} ". ToString (), "-i${file (" Src/main/jni/src/helper ")}". ToString (), "-i${file (" Src/main/jni/src/helpe R/utf8 ")}". ToString (), "-i${file (" Src/main/jni/src/ctbmodel ")}". ToString (), "- I${file ("Src/main/jni/src/ctbmodel/ctbalbum")} ". ToString (),"-i${file ("SRC/MAIN/JNI/SRC/CTBMODEL/CTB                       Albumparser ")}". ToString (), "-i${file (" Src/main/jni/src/ctbmodel/ctbbasemodel ")}". ToString (), "-i${file (" Src/main/jni/src/ctbmodel/ctbtrack ")}". ToString (), "-i${file (" Src/main/jn                       I/src/xml ")}". ToString (), "-i${file (" Src/main/jni/src/xml/xmlmodel ")}". ToString (), "-i${file (" Src/main/jni/src/xml/xmlmodel/xmlattrnode ")}". ToString (), "-i${file (" Src/main/jni/src/xml/xmlmodel/xmlbaseno                       De ")}". ToString (), "-i${file (" Src/main/jni/src/xml/xmlmodel/xmlelementnode ")}". ToString (), "-i${file (" Src/main/jni/src/xml/xmlmodel/xmltextnode ")}". ToString (), "-i${file (" Src/mai N/jni/src/xml/xmlutil ")}". ToString (), "-i${file (" Src/main/jni/src/xml/xmlutil/boostxmlutil ")}". Tostr ING (), "-i${file (" Src/main/jni/src/module ")}". ToString (), "-i${file (" src/main/                       Jni/src/ctbdatamanager ")}". ToString (), "-i${file (" Src/main/jni/src/sync/syncprocess ")}". ToString (), "-i${file (" Src/main/jni/src/sync/task ")}". ToString (), "-i${file (" src/main/jni/                       Src/synclog ")}". ToString (), "-i${file (" Src/main/jni/src/utils ")}". ToString (), "-i${file (" src/main/jni/Neon//external/android ")}". ToString (), "-i${file (" Src/main/jni/neon/external/openssl/include/openssl                       ")}". ToString (), "-i${file (" Src/main/jni/neon/external/openssl/include ")}". ToString (), "-i${file (" Src/main/jni/neon/external/expat/include ")}". ToString (), "-i${file (" Src/main/jni                       /src/synclog ")}". ToString (), "-i${file (" Src/main/jni/src/synclog ")}". ToString (), "-i${file (" Src/main/jni/src/synclog ")}". ToString (), "-i${file (" Src/main/jni/src/synclog ")}". Tostr ING (), "-i${file (" Src/main/jni/src/synclog ")}". ToString (), "-i${file (" Src/main /jni/src/synclog ")}". ToString ()]) Cflags.addall (["-ddebug"]) Ldlibs.addall boost_shared_libs LDLIBS.A Ddall (["Log", "M", "Z"]) ldflags.addall (["-llog", "-fvisibility=hidden", "-l/usr/lib", "-LM"]) STL = "gnustl_s Hared "} android.bUildtypes {release {minifyenabled = False Proguardfiles.add (file (' Proguard-rules.pro ')) }} android.sources {main {jni {source {Srcdir] Src/main /jni "Dependencies {app_abis.each {abi-Librar Y file ("Src/main/jni/neonlib/${abi}/libneon.a") Abi "${abi}" library file ("Src/main/jni/neon/ex Ternal/expat/${abi}/libexpat.a ") Abi" ${abi} "library file (" SRC/MAIN/JNI/OPENSSLLIB/${ABI}/LIBC                        Rypto.so ") Abi" ${abi} "library file (" src/main/jni/openssllib/${abi}/libssl.so ") Abi" ${abi} "                    }}}} jnilibs {source { Srcdir "Src/main/libs"}}}} android.productflavors {APP  _abis.each {abi--          Create (Getflavorname (ABI)) {ndk.with {abifilters.add (ABI)                Getprebuiltlibpaths (ABI). Each {path-, Ldflags.add ("-l" + path)} }}}}}tasks.all {task, println "Printtask#${task}" if (TASK.NAME.S        Tartswith (' link ')) {println "${task.name}.startswith (' link ')" Task.dependson copynativelibs }}task copynativelibs {["Debug", "release"].each {buildtype, App_abis.each {abi-def Lib            s = [:] Boost_shared_libs.each {name, libs[name] = "${getboostlibdir (ABI)}/lib${name}.so"  } Libs.crystax = Getlibcrystax (ABI) Libs.each {name, file--DependsOn                    Tasks.create (Name: "Copy-native-library-${name}-${abi}-${buildtype}", Type:copy) {from file Into GettargeTlibdir (ABI, BuildType)}}}}}task Stripnativelibs (dependson:copynativelibs) {[ "Debug", "release"].each {buildtype, App_abis.each {ABI, Def libs = [] Libs.addal L (boost_shared_libs) LIBS + = "Crystax" Libs.each {name--dependsOn tasks.create ( Name: "Strip-native-library-${name}-${abi}-${buildtype}", type:exec) {CommandLine getstripexecutable ( ABI), "--strip-unneeded", "${gettargetlibdir (ABI, BuildType)}/lib${name}.so"}}}}}d ependencies {Compile filetree (dir: ' Libs ', include: [' *.jar ']) Compile project (': Apiclient ') Compile ' De.greenro bot:eventbus:2.4.0 '}def Getndkdir () {if (System.env.ANDROID_NDK_ROOT! = null) return System.env.ANDROID_NDK_ROO T Properties Properties = New Properties () properties.load (Project.rootProject.file (' local.properties '). Newdatainput Stream ()) def Ndkdir= Properties.getproperty (' Ndk.dir ', null) if (Ndkdir = = null) throw new Gradleexception ("" "Ndk l                Ocation not found. Define location with Ndk.dir in the Local.properties file or with an android_ndk_root environment variable. "" ") return Ndkdir}def Getcrystaxndkdir () {def ndkdir = Getndkdir () if (! ( New File (Ndkdir, "Sources/crystax"). Exists ())) throw new Gradleexception ("" "' ${ndkdir} ' is not a crysta            X NDK. Edit Ndk.dir in local.properties or set android_ndk_root environment variable pointing to CrystaX ndk "") Re        Turn Ndkdir}def getflavorname (ABI) {switch (ABI) {case "Armeabi": Return "arm";            Case "armeabi-v7a": Return "ARM7" Case "arm64-v8a": Return "arm64" default:            Return Abi.replaceall ('-', ' _ ')}}def Gettoolchainname (ABI) {switch (ABI) {case ~/^armeabi.*/: Return "Arm-linux-andrOideabi "Case ~/^arm64.*/: Return" aarch64-linux-android "Case" MIPS ": Return" mipsel-            Linux-android "Case" MIPS64 ": Return" mips64el-linux-android "case [" x86 "," x86_64 "]: Return ABI Default:throw new Gradleexception ("Unsupported Abi: ' ${abi} '")}}def Gettoolchainprefix (A            BI) {switch (ABI) {case ~/^armeabi.*/: Return ' Arm-linux-androideabi ' case ~/^arm64.*/:            Return "aarch64-linux-android" Case "MIPS": Return "mipsel-linux-android" Case "MIPS64":            Return "mips64el-linux-android" case "x86": Return "i686-linux-android" Case "x86_64":     Return "X86_64-linux-android" Default:throw new Gradleexception ("Unsupported ABI: ' ${abi} '") }}def Gethostos () {if (Operatingsystem.current (). Islinux ()) return "Linux" if (Operatingsystem.current () . ISMACOSX ()) RetuRN "Darwin" if (Operatingsystem.current () iswindows ()) return "Windows" throw new Gradleexception ("Unsupporte D host OS ")}def Gethostarch () {def arch = System.getproperty (" os.arch ") switch (arch) {case [" x86_64 "," AMD            "]: Return" x86_64 "Case ~/^i[3456]86/: Case" x86 ": Return" x86 "default: throw new Gradleexception ("Can ' t detect host ' s CPU architecture: ' ${arch} '")}}def Gethosttag () {def tag = Gethostos () def arch = Gethostarch () if (Tag! = "Windows" | | Arch! = "x86") tag + = "-${arch}" return tag}d EF getstripexecutable (ABI) {def NDK = Getcrystaxndkdir () def toolchainname = Gettoolchainname (ABI) def toolchain Prefix = Gettoolchainprefix (ABI) def hosttag = Gethosttag () def strip = "${ndk}/toolchains/${toolchainname}-4.9/preb Uilt/${hosttag}/bin/${toolchainprefix}-strip "if (Operatingsystem.current (). iswindows ()) strip = Strip.replaceAl L ('/', ' \\\\ ') + '. exe '   Return strip}def getprebuiltlibpaths (ABI) {def paths = [] paths + = Getboostlibdir (ABI) paths + = Getlibcrystax Dir (ABI) return paths}def Gettargetlibdir (ABI, BuildType) {return ' ${builddir}/intermediates/binaries/${buildtype}/ ${getflavorname (ABI)}/lib/${abi} "}def Getlibcrystaxdir (ABI) {return" ${getcrystaxndkdir ()}/sources/crystax/libs/$ {abi} "}def Getlibcrystax (ABI) {return" ${getlibcrystaxdir (ABI)}/libcrystax.so "}def Getboostdir () {return" ${getcry Staxndkdir ()}/sources/boost/1.58.0 "}def Getboostincdir () {return" ${getboostdir ()}/include "}def GetBoostLibDir (ABI {return "${getboostdir ()}/libs/${abi}"}


Use Android Studo to develop NDK's gradle configuration (debug C code)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.