# Unable to see header file in Android Studio

This topic is 594 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi,

I have a problem on adding the header (.h) files to Android Studio. First of all, I tried to import my codes, and it has header-only files (interfaces and stuff). The thing is, when I import them, it doesn't show up in the Android Studio. Even when I create a new .h file, it doesn't show up as well. I've called include_directories for the folder that contains the .h files but still it doesn't show up. I've posted a screenshot that includes for the related cmake code. The filename is CharacterFriendship.h, as displayed in the explorer window in screenshot.

Can someone help me?

Cheers.

##### Share on other sites

Does this problem persist if you close Android Studio and open it again?

Android Studio creates various project files, which I believe are plain XML - you could open them in a text editor and see if it's lacking a line for your file, and if so, just add one.

You might also have some sort of exclusion rules operating which mean certain filenames would never show up - check the project settings.

##### Share on other sites

Yes it's still happening even when I close and open it.

The only xml exist is AndroidManifest.xml which has nothing to do with the files. I have no idea what others (and where) cause there's just too many files there (literally hundreds of them). Most xmls are values.xml with localization values, and the others are more on the UI stuff related to the IDE settings. Besides, it's kinda counter-productive if I manually change them outside the Android Studio if I found them. The only file that seem to care about the cpp files are, as far as I can tell, is the Cmake (Which therefore I show the code in the screenshot). The gradle only tells which cmake list the Android Studio wants to sync with. Please correct me if I'm wrong or if I miss something.

I start off from empty Android project with C++ support and C++ 11 (with rtti and exception), and add a few lines in the gradle such as preprocessor commands and ABIs. Then I modify the CMake like the screenshot to sync the files so it is shown in the IDE, and so it can be compiled. I don't think I add anything related to exclusion rules, unless the default Android Studio project has that exclusion rules, which I don't know about. Is it?

Forgot to mention, my android studio version is 2.2.2. I'm planning on trying to downgrade the version if this isn't solved soon, but I'm not sure if that's the issue.

apply plugin: 'com.android.application'

android {
compileSdkVersion 24
buildToolsVersion "24.0.3"
defaultConfig {
applicationId "com.www.www"
minSdkVersion 24
targetSdkVersion 24
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
externalNativeBuild {
cmake {
abiFilters "armeabi-v7a", "arm64-v8a", "x86", "x86_64"
arguments "-DANDROID_TOOLCHAIN=clang", "-DANDROID_STL=c++_static"
cppFlags "-std=c++11 -frtti -fexceptions -DANDROID -D__STDC_LIMIT_MACROS -DVK_NO_PROTOTYPES -DVK_USE_PLATFORM_ANDROID_KHR"
}
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
externalNativeBuild {
cmake {
path "CMakeLists.txt"
}
}
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:24.2.1'
testCompile 'junit:junit:4.12'
}



AndroidManifest.xml:

<?xml version="1.0" encoding="utf-8" ?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.www.www"
android:versionCode="1"
android:versionName="1.0">

<uses-sdk android:minSdkVersion="24" />

<uses-feature android:name="android.hardware.audio.low_latency" android:required="true" />
<uses-feature android:name="android.hardware.audio.output" android:required="true" />
<uses-feature android:name="android.hardware.audio.pro" android:required="true" />
<uses-feature android:name="android.hardware.screen.landscape" android:required="true" />
<uses-feature android:name="android.software.webview" android:required="true" />

<uses-feature android:name="android.hardware.touchscreen" android:required="false" />
<uses-feature android:name="android.software.leanback" android:required="false" />

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

<application
android:hasCode="false"
android:isGame="true"
android:label="www">
<activity
android:label="www"
android:name="android.app.NativeActivity"
android:screenOrientation="landscape"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen">
<meta-data android:name="android.app.lib_name" android:value="www" />
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.LEANBACK_LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>

Edited by away2903

##### Share on other sites
This is normal, :unsure:  Android Studio only use the files that you define in CMakeLists.txt file. Then it only includes the .cpp and the .h with the same name of the .cpp file, for example utils.cpp and utils.h. But if you include utils2.h inside of utils.cpp and this file is in the same folder that utils.cpp, it is not show in the Android Studios environment.

Do somebody tries the Visual Studio 2015 for compile Android C++ code? I think that the Android Studio developers not use the program to professional  Android C++ Applications :( , and i'm looking for alternatives to it.
Thanks,

Spear

##### Share on other sites

Oh god, so that's normal... well so far I use the ones that display the project files... that should show the .h files even though it does not guarantee being linked to the project (Might be just me being bad at cmake so far). Android Studio is also annoyingly show the folders based on the directories I included in Cmake (by the cpp/subdirectories you are linking... how confusing is that?) at same tree level. For example, I have Core folder inside an Engine folder... then both are displayed as siblings in the project explorer. It's so confusing.

I'd love to have the Android to work with VS, but I need it to support Android Nougat and it's just not there yet. It works though as I test the Android 19 to my galaxy s3 (debug mode), but professionally I don't know cause I haven't published anything with it yet. You may wanna try it cause it really works as easy as normal VS studio for desktop.

##### Share on other sites
Yes, I used the VS 2013 with Android Works (from Nvidia) for a professional project, and this works well. But I had problems with gradle and google-services and other libraries. I will test VS2015 and VS2017.

For us is better because we have the game running in the VS for the desktop version.

Android Studio is not ready for C ++ professional projects, with many files and your own paths, templates, inline files, etc.

1. 1
2. 2
3. 3
Rutin
19
4. 4
5. 5

• 14
• 30
• 13
• 11
• 11
• ### Forum Statistics

• Total Topics
631780
• Total Posts
3002313
×