I would like to build the sample projects included in the gear vr framework using Android Studio on Windows 8. I imported the "simple-sample" project (GVRf\Sample\simple-sample) into Android Studio 1.5, and configured the NDK to be the latest version: android-ndk-r10e
However, I kept getting this error when building the project:
limits: No such file or directory
the < limits > header is included in glm.hpp, located at "framework\src\main\jni\contrib\glm"
Here is my Application.mk file inside directory "\framework\src\main\jni"
APP_ABI := armeabi-v7a
APP_PLATFORM := android-19
#APP_STL := stlport_static
APP_STL := gnustl_static
NDK_TOOLCHAIN_VERSION := 4.8
ifndef OVR_MOBILE_SDK
OVR_MOBILE_SDK=../../ovr_sdk_mobile
endif
NDK_MODULE_PATH := $(OVR_MOBILE_SDK)
People suggested several ways to address this problem:
1. set NDK_TOLLCHAIN_VERSION := 4.4.3 (post)
2. set APP_STL := gnustl_static (post)
I tried both and neither worked. However, it seems like the problem is that the Application.mk file is ignored by Android Studio. Because I typed some junk in there and it didn't seem to affect anything.
So I also tried to configure the NDK by modifying build.gradle file inside the \framework folder:
android {
defaultConfig {
ndk {
stl "stlport_static"
}
}
}
Not much success either, don't know how to correctly set the values.
There is a line of words on the Gear VR guide website which might be relevant (my error is indeed at the JNI level):
NOTE: Do NOT install a CDT version higher than 8.0.2 or you will encounter parser errors at the JNI level, even though these will not affect building and running your GearVRf application.
Can someone please help? Thanks!
Related
All,
I am experimenting with this example.
https://www.truiton.com/2014/11/bound-service-example-android/
It has a service class (as in "extends service") that instantiates a chronometer and returns the time elapsed from the moment the app was started.
The code compiles in Android Studio and I can install and run the apk file on my dedicated embedded android target. The app runs fine.
I would like to be able to compile the example the code locally within AOSP. Specifically in the /packages/apps/ folder using a dedicated Android.mk file
The cleaned-up directory structure in Chrono_AOSP folder is given below
\---src
| Android.mk
| AndroidManifest.xml
|
+---java
| \---com
| \---ppp_aosp
| \---chrono
| BoundService.java
| MainActivity.java
|
\---res
+---drawable
+---drawable-v24
+---layout
+---mipmap-anydpi-v26
+---mipmap-hdpi
+---mipmap-mdpi
+---mipmap-xhdpi
+---mipmap-xxhdpi
+---mipmap-xxxhdpi
\---values
The code is successfully compiled into a .APK file ("mm -B -j4"). I then install the APK file (adb install chrono_aosp.apk). However, when I run the app, the app crashes "Chrono (AOSP) has stopped"
The Android.mk file is given below
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_PACKAGE_NAME := Chrono_AOSP
LOCAL_SRC_FILES := $(call all-java-files-under, src)
LOCAL_SDK_VERSION := current
LOCAL_MODULE_TAGS := tests
LOCAL_STATIC_JAVA_LIBRARIES := android-support-v7-appcompat
LOCAL_RESOURCE_DIR := $(LOCAL_PATH)/res
LOCAL_RESOURCE_DIR += prebuilts/sdk/current/support/v7/appcompat/res
LOCAL_AAPT_FLAGS := --auto-add-overlay
include $(BUILD_PACKAGE)
Can somebody tell me how to fix/troubleshoot my problem?
All,
I managed to get the app to compile and run.
I did a search for "AppCompatActivity" in the /packages/apps folder for my AOSP installation.
It returned a few hits in the java files for the Dialer app. I looked at the Android.mk file in Dialer app directory and used it as a reference (with minimal modifications) for my custom Android.mk
I've compiled OpenCV static libraries targeting android armeabi-v7a.
Now I'm trying to link my native C++ code with those libraries through a CMakeLists.txt file in Android Studio but this fails with this weird error :
~/opencv/modules/videoio/src/container_avi.cpp:0: error: undefined reference to 'stderr'
This code comes from the libopencv_videoio.a
The interresting part of the CMakeLists.txt file is this
# linking with static libraries
target_link_libraries(native-lib
dnn ml objdetect shape stitching superres videostab calib3d features2d highgui videoio imgcodecs video photo imgproc flann core
)
Isn't it supposed to find standard libraries automatically ?
EDIT 1:
Following is my Application.mk
...
NDK_TOOLCHAIN_VERSION := clang
APP_PLATFORM := android-21
APP_STL := c++_shared
...
NDK version taken from Changelog.md : r17b
EDIT 2:
As Dan suggested, I've added
"-DANDROID_PLATFORM=android-24"
to the cmake arguments
The most likely scenario is that you built opencv for android-23+ but native-lib has a minSdkVersion below that. See https://android.googlesource.com/platform/ndk/+/master/docs/user/common_problems.md#using-mismatched-prebuilt-libraries.
I'm a long time programmer but new to Android Studio. I have inherited some existing JNI library code intended to be run with ndk-build that already has its Android.mk file. It would be nice to reuse that. When I opened a new project with Android Studio and set the C++ support flag, it set itself up to use CMake instead of ndk-build. The documentation for Android Studio says both are available so I decided to try a simple test to see if I had found all the places that needed to change. It was a complete fail with error messages that seem to lead nowhere.
To recreate, create a new project ProjTest2 with Android Studio and check the Include C++ Support box. Accept the default Phone and Tablet form factor with a Minimum SDK of API 16: Android 4.1. Choose the Empty Activity. Accept the default Activity and Layout names. Accept the default Toolchain and do not check the boxes for Exceptions Support or Runtime. Run program, select device Android Emulator Nexus_5_API_24:5554. All is well; get message Hello from C++ on emulator screen.
Attempt to change to ndk-build. Open build.grade file for Module:app. Replace lines:
externalNativeBuild {
cmake {
path "CMakeLists.txt"
}
}
with:
externalNativeBuild {
ndkBuild {
path "jni/Android.mk"
}
}
Create a new folder jni in the directory ProjTest2/app. Create the file Android.mk in that folder with the following content:
# A simple test for the minimal standard C++ library
#
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := native-lib
LOCAL_SRC_FILES := $(LOCAL_PATH)/../src/main/cpp/native-lib.cpp
LOCAL_LDLIBS := -llog -landroid
include $(BUILD_SHARED_LIBRARY)
The build now fails claiming that it cannot find the target of #include <string> and that it cannot resolve the container 'std'. I find that I can clear the IDE error flags by adding LOCAL_C_INCLUDES += C:\Users\JWC\AppData\Local\Android\sdk\ndk-bundle\sources\cxx-stl\gnu-libstdc++\4.9\include to the Android.mk file but the resulting make still fails when it cannot find some of the sub-includes from <string>.
Did I miss something simple, or is this just not as easy as it seems it should be?
Edit:
Also needs file:
# Application.mk
APP_ABI := armeabi-v7a armeabi
APP_PLATFORM := android-21
APP_OPTIM := release
APP_STL := gnustl_static
CMake defaults to using the gnustl_static STL, whereas ndk-build defaults to using none.
Add the following to your project:
jni/Application.mk:
APP_STL := gnustl_static
There are a handful of these available. gnustl_static will match the cmake use, but you can see other choices in the official docs.
I'm trying to create an native executable for android and it keeps crashing. testing the file with readelf and objdump revivals that the file is considered to be an shared object file.
I'm using the r8e and compiling with ndk-build
test.c:
int main(){
return 0;
}
Android.mk:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_SRC FILES := test.c
LOCAL_MODULE := test
include(BUILD_EXECUTABLE)
--
Setting the app_platform to android-9 results in the creation of an executable file ( and no crashes).
Have you tried specifying arguments int args and char *argv[] for your main() method? Also, where are you trying to run it?
I confirm this bug... I had a project that compiled perfectly with ndk-r8, but when I switched to ndk-8e my executable did not build properly anymore.
I reported it here: https://code.google.com/p/android/issues/detail?id=55769
Here is the answer I got from google:
This is normal.
By default, when targetting API level 17 or higher, "Position Independent Executables" (a.k.a. PIE) are generated by the BUILD_EXECUTABLE rule.
These are executable binaries, but they are only supported on Android 4.1 or higher. See [1] for more details.
If you really don't want these (e.g. because you want your program to run on previous releases of the platform), you have two choices:
Target a lower API level.
Use 'APP_PIE := false' in your Application.mk
I have installed correctly the Android SDK, Android NDK, eclipse, and I have the last repository's cocos2d from git.
I have followed the steps in the wiki to generate a project and I have done correctly.
The problem comes when I run ./build_native.sh, I get this error:
Cannot find module with tag 'libjpeg' in import path
I have checked the Android.mk, and I suppose that the error is in the final zone:
LOCAL_WHOLE_STATIC_LIBRARIES := cocos_libpng_static
LOCAL_WHOLE_STATIC_LIBRARIES += cocos_jpeg_static
LOCAL_WHOLE_STATIC_LIBRARIES += cocos_libxml2_static
# define the macro to compile through support/zip_support/ioapi.c
LOCAL_CFLAGS := -DUSE_FILE32API
include $(BUILD_SHARED_LIBRARY)
$(call import-module,libjpeg)
$(call import-module,libpng)
$(call import-module,libxml2)
I have read the steps several times, and I didn't forget (I think) anything. Could someone who have been compiled the code help me please?
The complete error is:
Android NDK: jni/../../../cocos2dx/Android.mk: Cannot find module with tag 'libjpeg' in import path
Android NDK: Are you sure your NDK_MODULE_PATH variable is properly defined ?
Android NDK: The following directories were searched:
Android NDK:
make: Entering directory `/home/pipero/git_checkout/cocos2d-x/PiperoStest/android'
Thanks in advance.
EXTRA: I have created the project using the: $COCOS2D>create-linux-eclipse-project.sh and i can't open the project in eclipse neither to compile using ndk from eclipse directly.
EXTRA2: The steps are from HERE
EXTRA3: I already changed the NDK_ROOT_LOCAL="$LIBS/android-ndk-r7b"
ANDROID_SDK_ROOT_LOCAL="$LIBS/android-sdk-linux"
I followed steps below with version 0.12.0 (2012-03-05) and it worked:
1º Install NDK Android
2º Install SDK Android
3º Instal Android plug-in on Eclipse.
4º Download ./create-android-project.sh with NDK and SDK paths.
5º Compile a new project with ./create-linux-eclipse-project.sh
Choose ID (android). If you get a warning that means it cannot find NDK.
Name of the project
It'll be create on current folder.
6º Compile Cocos2d libs inside project folder with ./build_native.sh.
7º Create new Android project from source code in project's folder > android.
8º Run the project and it should appear Cocos2d wallpaper.
I fixed this by adding the following to Android.mk in the cocos2d directory:
$(call import-add-path, $(LOCAL_PATH)/platform/third_party/android/prebuilt)
This was added just before this section, which is at the bottom of the file:
$(call import-module,libjpeg)
$(call import-module,libpng)
$(call import-module,libtiff)
$(call import-module,libwebp)