[英]Android Studio with NDK-Build - Does not show C++ Files in Project Navigator
I'm using Android Studio with NDK-Build and it does not show the single C++ files, so I can't debug.我将 Android Studio 与 NDK-Build 一起使用,但它不显示单个 C++ 文件,因此我无法调试。 It only shows a cpp-Folder and insid ethe folder it shows some Static-Libraries, which I can not step in further.它只显示一个 cpp 文件夹,在文件夹内它显示了一些静态库,我无法进一步介入。 I remember that it was once possible to go inside these libraries (they opened like folders) and see the single cpp files.我记得曾经可以进入这些库(它们像文件夹一样打开)并查看单个 cpp 文件。
Here's my build.gradle file:这是我的 build.gradle 文件:
import java.util.regex.Pattern
import com.android.build.OutputFile
import org.apache.tools.ant.taskdefs.condition.Os
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
task('increaseVersionCode') << {
def buildFile = file("build.gradle")
def pattern = Pattern.compile("versionCode\\s+(\\d+)")
def manifestText = buildFile.getText()
def matcher = pattern.matcher(manifestText)
matcher.find()
def versionCode = Integer.parseInt(matcher.group(1))
def manifestContent = matcher.replaceAll("versionCode " + ++versionCode + "")
buildFile.write(manifestContent)
}
// DO NOT change the build.gradle on debug builds any longer, since this will lead to debugging not work and Android Studio / Gradle crash
tasks.whenTaskAdded { task ->
if (task.name == 'generateReleaseBuildConfig' /*|| task.name == 'generateDebugBuildConfig'*/) {
task.dependsOn 'increaseVersionCode'
}
}
task deleteGraphicsAssets(type: Delete) {
println 'Grade: Deleting unnecessary assets...'
delete "assets/1136p"
delete "assets/2048p"
}
preBuild.dependsOn deleteGraphicsAssets
android {
// Going higher means that we have to request to write to external storage (used for UUID): https://stackoverflow.com/questions/36084959/cant-create-a-directory-on-storage-emulated-0-on-emulator
// But GameAnalytics reqires 24, let's see if it still works this way
compileSdkVersion 22
buildToolsVersion '25.0.3' // should be 25 for newer version
defaultConfig {
applicationId "com.forestringgames.apps.towerduel"
minSdkVersion 15
// Going higher means that we have to request to write to external storage (used for UUID): https://stackoverflow.com/questions/36084959/cant-create-a-directory-on-storage-emulated-0-on-emulator
// But GameAnalytics reqires 24, let's see if it still works this way
targetSdkVersion PROP_TARGET_SDK_VERSION
versionCode 1602
versionName "1.0"
// multiDexEnabled true
externalNativeBuild {
ndkBuild {
if (!project.hasProperty("PROP_NDK_MODE") || PROP_NDK_MODE.compareTo('none') != 0) {
// skip the NDK Build step if PROP_NDK_MODE is none
targets 'cocos2dcpp'
arguments 'NDK_TOOLCHAIN_VERSION=4.9'
arguments 'APP_PLATFORM=android-' + PROP_TARGET_SDK_VERSION
// arguments 'NDK_CCACHE='+System.getenv('NDK_CCACHE')
// println 'A message which is logged at QUIET level:'+System.getenv('HOME')
// println 'A message which is logged at QUIET level:'+System.getenv('NDK_CCACHE')
// println "$System.env.HOME"
def module_paths = [project.file("../../FRGEngine/cocos2d").absolutePath,
project.file("../../FRGEngine/cocos2d/cocos").absolutePath,
project.file("../../FRGEngine/cocos2d/external").absolutePath]
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
// should use '/'
module_paths = module_paths.collect { it.replaceAll('\\\\', '/') }
arguments 'NDK_MODULE_PATH=' + module_paths.join(";")
} else {
arguments 'NDK_MODULE_PATH=' + module_paths.join(':')
}
arguments '-j' + Runtime.runtime.availableProcessors()
abiFilters.addAll(PROP_APP_ABI.split(':').collect { it as String })
}
}
}
testApplicationId 'Test'
}
// only added for android debugging
externalNativeBuild {
ndkBuild {
if (!project.hasProperty("PROP_NDK_MODE") || PROP_NDK_MODE.compareTo('none') != 0) {
// skip the NDK Build step if PROP_NDK_MODE is none
path "jni/Android.mk"
}
}
}
sourceSets.main {
java.srcDir "src"
res.srcDir "res"
jniLibs.srcDir "libs"
manifest.srcFile "AndroidManifest.xml"
assets.srcDir "assets"
}
splits {
abi {
enable true
reset()
include 'armeabi-v7a'
//, 'armeabi', 'armeabi-v7a', 'x86' - what about arm64? Test it with Crashlytics
universalApk false //true
}
// density {
// enable true
// reset()
// include 'mdpi', 'hdpi', 'xhdpi', 'xxhdpi', 'xxxhdpi'
// compatibleScreens 'small', 'normal', 'large', 'xlarge'
//
// }
}
signingConfigs {
release {
if (project.hasProperty("RELEASE_STORE_FILE")) {
storeFile file(RELEASE_STORE_FILE)
storePassword RELEASE_STORE_PASSWORD
keyAlias RELEASE_KEY_ALIAS
keyPassword RELEASE_KEY_PASSWORD
}
}
}
buildTypes {
release {
minifyEnabled false // Warning: is this a good idea?
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
if (project.hasProperty("RELEASE_STORE_FILE")) {
signingConfig signingConfigs.release
}
externalNativeBuild {
ndkBuild {
arguments 'NDK_DEBUG=0'
}
}
}
debug {
// debuggable true
// jniDebuggable true
externalNativeBuild {
ndkBuild {
arguments 'NDK_DEBUG=1'
}
}
}
}
}
crashlytics {
enableNdk = true
androidNdkOut = 'obj'
androidNdkLibsOut = 'libs'
}
repositories {
mavenCentral()
}
dependencies {
// compile 'com.android.support:multidex:1.0.1'
compile fileTree(dir: 'libs', include: ['*.jar'])
compile project(':libcocos2dx')
// compile project(':BaseGameUtils')
// compile 'com.android.support:multidex:1.0.0'
compile 'com.facebook.android:facebook-android-sdk:4.8.0'
// compile 'com.google.android.gms:play-services-auth:9.0.0'
// integration guide (with latest version numbers: https://fabric.io/downloads/gradle)
// Crashlytics KitminifyEnabled
compile('com.crashlytics.sdk.android:crashlytics:2.6.8@aar') {
transitive = true
}
// NDK Kit
compile('com.crashlytics.sdk.android:crashlytics-ndk:1.1.6@aar') {
transitive = true
}
// compile('com.crashlytics.sdk.android:crashlytics:2.7.0-SNAPSHOT@aar') {
// transitive = true;
// }
//
// compile('com.crashlytics.sdk.android:crashlytics-ndk:1.2.0-SNAPSHOT:debug@aar') {
// transitive = true;
// }
compile 'net.bytebuddy:byte-buddy:1.7.3'
compile 'net.bytebuddy:byte-buddy-android:1.7.3'
// compile 'com.google.firebase:firebase-auth:11.0.1'
compile 'com.google.android.gms:play-services-auth:11.0.0'
compile 'com.google.android.gms:play-services-games:11.0.0'
compile 'com.google.firebase:firebase-invites:11.0.0'
compile 'com.google.firebase:firebase-messaging:11.0.0'
compile 'com.anjlab.android.iab.v3:library:1.0.+'
compile files('Frameworks/Fmod/prebuilt/android/fmod.jar')
// // use latest version instead version number: https://github.com/GameAnalytics/GA-SDK-ANDROID
// compile 'com.gameanalytics.sdk:gameanalytics-android:3.5.0'
compile fileTree(include: ['*.jar'], dir: 'Frameworks/Jars')
//
}
apply plugin: 'com.google.gms.google-services'
If I remove the following bit, the cpp-folder is gone - so it definitely does something...but not show the single files:如果我删除以下位,则 cpp 文件夹消失了 - 所以它肯定做了一些事情......但不显示单个文件:
externalNativeBuild {
ndkBuild {
if (!project.hasProperty("PROP_NDK_MODE") || PROP_NDK_MODE.compareTo('none') != 0) {
// skip the NDK Build step if PROP_NDK_MODE is none
path "jni/Android.mk"
}
}
}
Here's also the Android.mk:这也是Android.mk:
$(info ANDROID.MK FILE PARSING)
LOCAL_PATH := $(call my-dir)
CLASSES_PATH := $(LOCAL_PATH)/../../../Classes
PHOTON_SDK_ROOT := $(LOCAL_PATH)/../Frameworks/Photon
#
#
include $(CLEAR_VARS)
#
#
$(call import-add-path,$(LOCAL_PATH)/../../../FRGEngine/cocos2d)
$(call import-add-path,$(LOCAL_PATH)/../../../FRGEngine/cocos2d/external)
$(call import-add-path,$(LOCAL_PATH)/../../../FRGEngine/cocos2d/cocos)
#THE TRICK IS TO ACTUALLY NOT NAME FOLDERS TWICE - IF IMPORTING FRAMEWORKS HERE - THEN IMPORT /Fmod LATER - UNDER FRAMRWORKS
$(call import-add-path,$(LOCAL_PATH)/../Frameworks)
LOCAL_MODULE := cocos2dcpp_shared
LOCAL_MODULE_FILENAME := libcocos2dcpp
LOCAL_SRC_FILES := main.cpp \
gameanalytics/GameAnalyticsJNI.cpp \
$(subst $(LOCAL_PATH)/,,$(wildcard $(CLASSES_PATH)/*.cpp)) \
$(subst $(LOCAL_PATH)/,,$(wildcard $(CLASSES_PATH)/*.c)) \
$(subst $(LOCAL_PATH)/,,$(wildcard $(CLASSES_PATH)/../FrameworksCrossPlatform/libfixmath/*.c)) \
$(subst $(LOCAL_PATH)/,,$(wildcard $(CLASSES_PATH)/../FrameworksCrossPlatform/libfixmath/*.cpp)) \
$(subst $(LOCAL_PATH)/,,$(wildcard $(CLASSES_PATH)/../FrameworksCrossPlatform/ScreenLog/*.cpp)) \
$(subst $(LOCAL_PATH)/,,$(wildcard $(CLASSES_PATH)/../FrameworksCrossPlatform/PlayFabClientSDK/*.c)) \
$(subst $(LOCAL_PATH)/,,$(wildcard $(CLASSES_PATH)/../FrameworksCrossPlatform/PlayFabClientSDK/*.cpp)) \
$(subst $(LOCAL_PATH)/,,$(wildcard $(CLASSES_PATH)/../FrameworksCrossPlatform/GameAnalytics/*.cpp))
LOCAL_CFLAGS += -fpermissive
ifeq ($(DISTRIBUTION_TESTING),1)
$(info ADDING DISTRIBUTION TESTING PREPROCESSOR FLAG)
LOCAL_CFLAGS += -DDISTRIBUTION_TESTING=1
endif
ifeq ($(DISTRIBUTION_LIVE),1)
$(info ADDING DISTRIBUTION LIVE PREPROCESSOR FLAG)
LOCAL_CFLAGS += -DDISTRIBUTION_LIVE=1
endif
# _COCOS_HEADER_ANDROID_BEGIN
LOCAL_C_INCLUDES := $(CLASSES_PATH) \
$(CLASSES_PATH)/../FrameworksCrossPlatform/libfixmath \
$(CLASSES_PATH)/../FrameworksCrossPlatform/ConcurrentQueue \
$(CLASSES_PATH)/../FrameworksCrossPlatform/PlayFabClientSDK \
$(CLASSES_PATH)/../FrameworksCrossPlatform/ScreenLog \
$(CLASSES_PATH)/../FrameworksCrossPlatform/GameAnalytics \
$(CLASSES_PATH)/../FrameworksCrossPlatform \
$(PHOTON_SDK_ROOT) \
$(LOCAL_PATH)/../Frameworks/Fmod/lowlevel/inc \
$(LOCAL_PATH)/gameanalytics
# _COCOS_HEADER_ANDROID_END
LOCAL_STATIC_LIBRARIES := cocos2dx_static loadbalancing-cpp-static-prebuilt photon-cpp-static-prebuilt common-cpp-static-prebuilt
LOCAL_SHARED_LIBRARIES := fmod
LOCAL_SHARED_LIBRARIES += fmodstudio
# _COCOS_LIB_ANDROID_BEGIN
include $(BUILD_SHARED_LIBRARY)
$(call import-module,.)
# _COCOS_LIB_IMPORT_ANDROID_BEGIN
# _COCOS_LIB_IMPORT_ANDROID_END
# PHOTON
$(call import-add-path,$(PHOTON_SDK_ROOT)/LoadBalancing-cpp/lib)
$(call import-module,loadbalancing-cpp-prebuilt)
# FMOD
#THE TRICK IS TO ACTUALLY NOT NAME FOLDERS TWICE - IF IMPORTING FRAMEWORKS HERE - THEN IMPORT /Fmod LATER - UNDER FRAMRWORKS
$(call import-module,Fmod/prebuilt/android)
# _COCOS_LIB_ANDROID_END
This is how it looks in Android Studio:这是它在 Android Studio 中的样子:
In my case it was the NDK that was left blank in Project Structure | SDK Location | Android NDK Location
就我而言, Project Structure | SDK Location | Android NDK Location
留空的是 NDK Project Structure | SDK Location | Android NDK Location
Project Structure | SDK Location | Android NDK Location
Project Structure | SDK Location | Android NDK Location
even if the NDK was installed with the SDK Manager. Project Structure | SDK Location | Android NDK Location
即使 NDK 与 SDK 管理器一起安装。
After clicking the combobox and selecting the NDK, the cpp
folder started to be populated with my native sources.单击组合框并选择 NDK 后, cpp
文件夹开始填充我的本机源。
ive been off a while, what happened to comments :)我离开了一段时间,评论发生了什么:)
anyway, according to this document you should have The cpp group folder under the java folder.无论如何,根据此文档,您应该在 java 文件夹下有 cpp 组文件夹。
check here for instructions Add C and C++ Code to Your Project在此处查看说明将 C 和 C++ 代码添加到您的项目
When I had this problem with a CMake project, the solution was that I had not added the .cpp files correctly to CMakeLists.txt当我在 CMake 项目中遇到此问题时,解决方案是我没有将 .cpp 文件正确添加到 CMakeLists.txt
When I edited CMakeLists with an entry like this当我用这样的条目编辑 CMakeLists 时
add_library( # Sets the name of the library.
myNative-lib
# Sets the library as a shared library.
SHARED
# Provides a relative path to your source file(s).
myCppFile.cpp )
then I could see myCppFile.cpp.然后我可以看到 myCppFile.cpp。
What version are you using for your gradle build tools?你的 gradle 构建工具使用的是什么版本? I was previously using an older version until I changed it to 3.4.2 and I could see my files in the project hierarchy.我以前使用的是旧版本,直到我将其更改为 3.4.2,并且可以在项目层次结构中看到我的文件。
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.4.2'
}
}
First download NDK ...首先下载NDK...
Go to File - Project structure and click on SDK location tab转到文件 - 项目结构并单击 SDK 位置选项卡
Then move your path to C:// with full project ( do no try to import only modules inside project ) ...然后将您的路径移动到带有完整项目的 C://(不要尝试仅导入项目内的模块)...
Import project again but from C://再次导入项目,但从 C://
If you dont have suceess try with other paths , try , try , try如果您没有成功尝试其他路径,请尝试,尝试,再尝试
You must try because problem is that you must find correct path for your CmaleLists.txt ...你必须尝试,因为问题是你必须为你的 CmaleLists.txt 找到正确的路径......
( example # Set the path to the Oboe library directory set (OBOE_DIR ../../../../..) ...... etc ) ... But sometimes path is not path you see ... (例如#设置双簧管库目录集的路径(OBOE_DIR ../../../../..)......等等)......但有时路径不是你看到的路径.. .
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.