Fixed
Status Update
Comments
do...@google.com <do...@google.com> #2
Just to add if i update my app/build.gradle file to explicitly specify the include path:
externalNativeBuild {
cmake {
cppFlags "-std=c++14 -I/Users/donturner/Code/workspace-android/TestIncludes/app/extra"
}
}
Then the indexer works correctly.
externalNativeBuild {
cmake {
cppFlags "-std=c++14 -I/Users/donturner/Code/workspace-android/TestIncludes/app/extra"
}
}
Then the indexer works correctly.
jo...@google.com <jo...@google.com> #3
After fixing the absolute path in CMakeLists.txt this issue doesn't repro for me.
You could try attaching another project zip with .externalNativeBuild folder included
You could try attaching another project zip with .externalNativeBuild folder included
do...@google.com <do...@google.com> #4
Here's the steps to reproduce this issue:
1) Start new project called "MyApplication"
2) Choose "Native C++", C++ standard=C++14, click Finish
3) Change view to "Project"
4) Right click on "MyApplication" folder and create a new folder called "mysharedcode"
5) Create a new file in the "mysharedcode" folder called "MySharedObject.h" and add the following code after the include guard:
class MySharedObject{
public:
MySharedObject(std::string name) : mName(name){}
std::string getName(){return mName; }
private:
std::string mName;
};
6) Edit app/src/main/cpp/CMakeLists.txt to include the path to this header file:
include_directories(../../../../mysharedcode)
7) Click on Build->Refresh Linked C++ project
8) Add MySharedObject.h as an #include in app/src/main/cpp/native-lib.cpp and use MySharedObject.
#include <jni.h>
#include <string>
#include <MySharedObject.h>
extern "C" JNIEXPORT jstring JNICALL
Java_com_example_myapplication_MainActivity_stringFromJNI(
JNIEnv *env,
jobject /* this */) {
std::string hello = "Hello from C++";
MySharedObject m("test");
return env->NewStringUTF(m.getName().c_str());
}
9) Do Build->Make Project to ensure project compiles successfully.
Expected result
In the editor window MySharedObject is found by the indexer and autocomplete works
Actual result
In the editor window MySharedObject is not found by the indexer and the #include directive is shown in red.
Workaround: File->Sync Project with Gradle Files
jomof@ suggested that when CMakeLists.txt is edited the IDE should prompt the user to sync, thus avoiding many hours of head scratching.
1) Start new project called "MyApplication"
2) Choose "Native C++", C++ standard=C++14, click Finish
3) Change view to "Project"
4) Right click on "MyApplication" folder and create a new folder called "mysharedcode"
5) Create a new file in the "mysharedcode" folder called "MySharedObject.h" and add the following code after the include guard:
class MySharedObject{
public:
MySharedObject(std::string name) : mName(name){}
std::string getName(){return mName; }
private:
std::string mName;
};
6) Edit app/src/main/cpp/CMakeLists.txt to include the path to this header file:
include_directories(../../../../mysharedcode)
7) Click on Build->Refresh Linked C++ project
8) Add MySharedObject.h as an #include in app/src/main/cpp/native-lib.cpp and use MySharedObject.
#include <jni.h>
#include <string>
#include <MySharedObject.h>
extern "C" JNIEXPORT jstring JNICALL
Java_com_example_myapplication_MainActivity_stringFromJNI(
JNIEnv *env,
jobject /* this */) {
std::string hello = "Hello from C++";
MySharedObject m("test");
return env->NewStringUTF(m.getName().c_str());
}
9) Do Build->Make Project to ensure project compiles successfully.
Expected result
In the editor window MySharedObject is found by the indexer and autocomplete works
Actual result
In the editor window MySharedObject is not found by the indexer and the #include directive is shown in red.
Workaround: File->Sync Project with Gradle Files
jomof@ suggested that when CMakeLists.txt is edited the IDE should prompt the user to sync, thus avoiding many hours of head scratching.
do...@google.com <do...@google.com> #5
I've been continuing to experience this problem.
When creating a new project using the steps above I'm able to get the indexer working correctly by using File->Sync Project with Gradle files, however, this doesn't work when adding the shared code folder to an existing project.
To get the indexer working in this scenario I had to:
- Close Android Studio
- Open Finder (I'm on a mac) and navigate to /Users/donturner/Library/Caches/AndroidStudioPreview3.4/
- Delete everything in this folder
- Reopen Android Studio
Only then did the indexer pick up the change.
The most ironic part about this is that I must've tried using File->Invalidate Caches/Restart hundreds of times whilst investigating this issue. It appears that this feature doesn't actually invalidate all of Android Studio's caches, which is why they must be deleted manually.
As well as fixing the indexer, the "invalidate caches" feature should also be fixed to actually do what it's supposed to do.
Upping the severity because this completely blocked development for me for ~3 days and is affecting top partners as well.
When creating a new project using the steps above I'm able to get the indexer working correctly by using File->Sync Project with Gradle files, however, this doesn't work when adding the shared code folder to an existing project.
To get the indexer working in this scenario I had to:
- Close Android Studio
- Open Finder (I'm on a mac) and navigate to /Users/donturner/Library/Caches/AndroidStudioPreview3.4/
- Delete everything in this folder
- Reopen Android Studio
Only then did the indexer pick up the change.
The most ironic part about this is that I must've tried using File->Invalidate Caches/Restart hundreds of times whilst investigating this issue. It appears that this feature doesn't actually invalidate all of Android Studio's caches, which is why they must be deleted manually.
As well as fixing the indexer, the "invalidate caches" feature should also be fixed to actually do what it's supposed to do.
Upping the severity because this completely blocked development for me for ~3 days and is affecting top partners as well.
tg...@google.com <tg...@google.com>
tg...@google.com <tg...@google.com> #6
Hi Don, this should have been fixed in newer 3.4 previews. Please reopen this bug if you still have issues. Thank you!
sh...@gmail.com <sh...@gmail.com> #7
deleted
Description
AI-183.4588.61.34.5173923, JRE 1.8.0_152-release-1248-b01x64 JetBrains s.r.o, OS Mac OS X(x86_64) v10.14.1, screens 1680x1050, 1920x1200; Retina
Android Gradle Plugin: 3.4.0-alpha08
Gradle: 5.1
NDK: from local.properties: 19.0.5106443-beta1; latest from SDK: (not found);
LLDB: pinned revision 3.1 not found; latest from SDK: (package not found);
CMake: from local.properties: (not specified); latest from SDK: 3.10.2; from PATH: (not found);
Source: user_sentiment_feedback
IMPORTANT: Please read
When I try to include C++ header files from another directory Android Studio shows those files in red. The project compiles successfully. I'm using `target_include_directories` in my CMakeLists.txt to add the paths to those files.
Attached is a test project which was created using the Android Studio project wizard, specifying the C++ template, with C++14 toolchain. Here's a screenshot of native-lib.cpp includes the `ExtraObject` class defined in app/extra/ExtraObject.h. Note that the include is shown in red, as is the use of `ExtraObject`.