Android filesystem includes - android

I am developing a native Android app, and I need access to GraphicBuffer.h (which is located in frameworks/base/include)
So I added the following to my Android.mk
#Android includes
LOCAL_C_INCLUDES += \
$(MYDROID)/frameworks/base \
$(MYDROID)/frameworks/base/include
The problem is that GraphicBuffer.h includes a bunch of other header files, and I don't want to have to add the paths to all of them in my makefile. What is the correct way to do this?
Update: While I would LOVE to know the correct way of doing this for the future, in this case, all that was needed was
#Android includes
LOCAL_C_INCLUDES += \
$(MYDROID)/frameworks/base/include \
$(MYDROID)/hardware/libhardware/include \
$(MYDROID)/system/core/include

You're supposed to use NDK to build native application.
What you're doing is trying to include header from Android source. This is not guaranteed to work on all devices, since this is not public API.

Related

How to include util-linux in AOSP?

How do I include util-linux from here in AOSP? Where should I add this util-linux folder in AOSP so that I can build AOSP and these utils could be added in /system/bin/ or /system/xbin/? And is there any specific Makefile or Android.mk that I need to make it to compile with Android build?
I have added an application from util-linux package in AOSP.
Here's how I did it. I added the util-linux (2.34) from https://mirrors.edge.kernel.org/pub/linux/utils/util-linux/v2.34/util-linux-2.34.tar.gz in external of AOSP folder.
I just wanted to add chrt from util-linux. Therefore, I run the normal make command in util-linux to see what files are compiled for chrt. I took a note and created an Android.mk accordingly. I am sure there's a better way to do it hierarchically by making the library first and then make the chrt executable. However, this works too.
I added the following Android.mk at external\util-linux\. The Android.mk looks like the following:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := sohamchrt
LOCAL_SRC_FILES := schedutils/chrt.c lib/blkdev.c lib/canonicalize.c \
lib/crc32.c lib/crc32c.c lib/idcache.c lib/fileutils.c \
lib/ismounted.c lib/color-names.c lib/mangle.c lib/match.c lib/mbsalign.c \
lib/mbsedit.c lib/md5.c lib/pager.c lib/parse-date.c lib/pwdutils.c lib/randutils.c \
lib/setproctitle.c lib/strutils.c lib/timeutils.c lib/ttyutils.c lib/exec_shell.c \
lib/strv.c lib/sha1.c lib/signames.c lib/linux_version.c lib/loopdev.c \
lib/plymouth-ctrl.c lib/cpuset.c lib/path.c lib/procutils.c lib/sysfs.c
LOCAL_CFLAGS = -DHAVE_NANOSLEEP -include config.h \
-isystem bionic/libc/upstream-openbsd/android/include
LOCAL_C_INCLUDES := $(LOCAL_PATH)/include
include $(BUILD_EXECUTABLE)
Now, when I run m -j8 iso_img, then Android tries to compile sohamchrt. I named the package sohamchrt because chrt is already provided by toybox which have limitations.
The problem is util-linux is not fully compatible with bionic. So, I needed to make some changes to some .c and .h files such as fileutils.c, include/c.h, etc.
After successful compilation, the binary sohamchrt appears in /system/bin when Android is running, and it works with no issues.
This is also a guide on how you can add a C source file for a userspace executable binary in AOSP.
It's always worth checking whether a library you want to add already exists at https://android.googlesource.com/. In your case, unfortunately, it does not.
As util-linux does not come with an Android.bp. You will have to understand how util-linux is built and how Soong works to create a custom Android.bp for integration. The correct folder to place it would be external/util-linux/.
Maybe you will want to take a shortcut and just add util-linux as prebuilt binaries. That will reduce the effort.
Please check licensing issues first, though.

MAKE problems in Android Project enabled with cocos2dx - "No rule to make target"?

BACKGROUND:
I'm following a tutorial online: Game apps in Android by Todd Perkins
- It's been very straightforward other than the hiccups that come with setting up NDK with eclipse, which I've managed to solve.
Problem:
I'm stuck at the point where I want my cocos2dx code to respond to a touch event and based on that, call Java android code from an activity.
I've added a bunch of screen shots below to show you how I've set everything up:
When I run build_native.sh:
Now I've made sure that I've linked my folders correctly in the project.
Below is a screen shot of the "linked" JNI folder(jni_linked), along with JniURL.cpp and JniURL.h:
and here's what my Android.mk file looks like:
I've double/triple checked the path of my Jni folder and it is:
C:\Users\DarkRaveDev\Documents\cocos2d-x-2.0.1\cocos2dx\platform\android\jni
Do I need to change the Android.mk file to have this line:
LOCAL_SRC_FILES := helloworld/main.cpp \
../../Classes/AppDelegate.cpp \
../../jni_linked/JniURL.cpp \
../../Classes/HelloWorldScene.cpp
It's probably treating:
/../../../cocos2dx/platform/android/jni/JniURL.cpp \
as starting with an absolute path instead of a relative path. It probably should be:
$(LOCAL_PATH)/../../../cocos2dx/platform/android/jni/JniURL.cpp \
or maybe:
../../../cocos2dx/platform/android/jni/JniURL.cpp \

Compiling and using OpenSSL for Android, on windows using eclipse

I am developing an Android app on windows, using eclipse.
I would like to use OpenSSL for my Android application. It needs to be used with C++ via NDK.
I tried to download fries' OpenSSL source code from https://github.com/fries/android-external-openssl and build it.
I read the README.android file, but I didn't understand what these instructions are for.
Do I need to download the OpenSSL source code in addition to the fries source code?
I have tried putting all the files from Fries' into my jni folder of the Android project. It complained about not finding e_os.h and openssl/crypto.h and others like that.
More specifically:
In file included from D:/Projects/Fatal/Android/OpenSSL/jni/ssl/s2_meth.c:59:
D:/Projects/Fatal/Android/OpenSSL/jni/ssl/ssl_locl.h:124:18: error: e_os.h: No such file or directory
D:/Projects/Fatal/Android/OpenSSL/jni/ssl/ssl_locl.h:126:28: error: openssl/buffer.h: No such file or directory
D:/Projects/Fatal/Android/OpenSSL/jni/ssl/ssl_locl.h:127:26: error: openssl/comp.h: No such file or directory
I am not sure why it doesn't find those files, I tried to add all sort of paths into LOCAL_C_INCLUDES in all sort of Android.mk files, but nothing worked.
I would like to know how to build OpenSSL for Android. Thank you.
I know this is old, but I kept coming across this when I was searching for this problem. In the case that you are building a standalone OpenSSL to go with your project and are getting this error, I found a solution as per this thread:
In openssl-android/crypto, openssl-android/ssl, and openssl-android/apps, you'll find a variable declaration for local_c_includes that is something like this:
local_c_includes := \
$(NDK_PROJECT_PATH) \
$(NDK_PROJECT_PATH)/crypto/asn1 \
$(NDK_PROJECT_PATH)/crypto/evp \
$(NDK_PROJECT_PATH)/include \
$(NDK_PROJECT_PATH)/include/openssl
If you've placed your openssl-android directory in your Android project in the project/jni directory, then these variables no longer point to the correct location. The way I solved it was to modify these paths to be relative to LOCAL_PATH:
local_c_includes := \
$(LOCAL_PATH)/.. \
$(LOCAL_PATH)/asn1 \
$(LOCAL_PATH)/evp \
$(LOCAL_PATH)/../include \
$(LOCAL_PATH)/../include/openssl
Remember, you'll have to do this for each of the directories you're trying to build (crypto, ssl, or apps).
I realized that the fries' github is just something to patch the source of OpenSSL, it's not a stand alone OpenSSL for android.
It is required because it provide Android.mk files which are required by ndk-build of ndk. You don't want to build it using standard gcc because you want to build it for Android.

Per-file CPPFLAGS in Android.mk

I'm working on an Android.mk file in which, for a single module, one of the files needs different CPPFLAGS; namely, it needs -frtti enabled, while others need the Android default of -fno-rtti.
The obvious solution was target-specific variables, but oddly they do not seem to affect compilation, even with some fiddling to ensure the values should be fixed at the right time.
Here's an extract from my Android.mk (names changed to protect me):
LOCAL_MODULE := foo_bar
LOCAL_SRC_FILES := \
foo_bar.cpp \
foo_baz.cpp
my_intermediates:= $(local-intermediates-dir)/foo_baz.o
$(my_intermediates): LOCAL_CPPFLAGS := -frtti
I have tried simply doing foo_baz.o: in lieu of $(my_intermediates), and have tried substituting += for := to no change.
So, is there an Android-specific way to override CPPFLAGS (or CFLAGS) for a specific source file?
(In this case I'm using the Eclair Android sources, though it may apply to the NDK; see my answer, below.)
As is usual, having asked the question after spending a lot of time on it, I have found the answer in short order. I need to use PRIVATE_CPPFLAGS instead of LOCAL_CPPFLAGS.
However, this only appears to be the case for the Android source distribution (at least Eclair) and NDK r6b. If I was using NDK r6, this probably would have worked as it stands.
The easiest way to have different parameters for some source files is to group these files in Android.mk together to produce a static library include $(BUILD_STATIC_LIBRARY) which will then be listed in LOCAL_STATIC_LIBRARIES for the resulting shared object.

browser plugin for default android browser

I would like to develop a plugin for the default android browser which would specify the category of sites in the google search result. The android browser dont explicitly show plugin architecture. I would like to know how that can be done and any reference materials related to that.
Thanks,
I recently tried to make an android plugin and found many questions on SO but not many detailed answers, so I'd thought I'd share my research here even though the question is quite old now. I'm not sure if a plugin is really what you want to do here since you could probably use google's JSON/ATOM Custom Search API and parse that, but nonetheless I give details on how to get plugins working on Android. I hope it is useful for others.
If you look here: PluginManager.java you will see the following lines:
// Only plugin matches one of the signatures in the list can be loaded
// inside the WebView process
private static final String SIGNATURE_1 = "308204c5..."
The signature used here is the one for the Adobe Flash plugin (support for which has now been dropped by Adobe.)
and further down here you will see:
if (SystemProperties.getBoolean("ro.secure", false)) {
boolean signatureMatch = false;
for (Signature signature : signatures) {
for (int i = 0; i < SIGNATURES.length; i++) {
if (SIGNATURES[i].equals(signature)) {
signatureMatch = true;
break;
}
}
}
if (!signatureMatch) {
return false;
}
}
This means that if ro.secure=0 then it won't check the signatures - it would only allow the flash plugin otherwise.
ro.secure is a build property that you can set if you have root privaleges for your device or you have a dev build (type adb shell getprop ro.secure to find out what you have). You can research how to change this if necessary. I was using a Qualcomm Snapdragon MDP8960 which is development board which had ro.secure=0 already. To get your plugin signature included in android you'll have to talk to someone in charge - not sure how feasible this is at present.
Now to write a plugin - you can find an example called SampleBrowserPlugin in the android sourcetree (make sure you have a 64 bit linux machine if you want to build it - type make SampleBrowserPlugin from the source tree root. You might need to set up the build configuration first using lunch and you can find instructions on the android source tree site)
I actually grabbed the source I needed from android source on github and made an NDK build of the source as I am more familiar with how to do this than modifying the android build scripts. It will also be a lot faster than downloading the whole android tree - you can see what to download by looking at what is included in Android.mk (see below).
Basically, I pulled the shared object libraries that I needed from the device to make sure my plugin would be compatible. They were in /system/lib on my device: (e.g. type adb pull /system/libnativehelper.so etc from the directory where you want them stored)
get the following:
libnativehelper.so
libandroid.so
libutils.so
libcutils.so
libEGL.so
libGLESv2.so
libskia.so
Put them where SO_LIB_PATH points to in Android.mk (see below and change Path as necessary).
Then after installing the NDK sdk you should be able to use the following build script - don't need a 64 bit machine - (you can install winbash, use cygwin, or a linux virtual machine e.g. Oracle VM VirtualBox:
(Place these files in C:/Path/BrowserPlugin/jni/ and make sure the ndk-build command is on your path)
(if you're on linux remove the .cmd from ndk-build.cmd)
build.sh:
#!/bin/bash
echo -e "Mode\t\t: Debug"
OPTIM=debug
### ---------------- Generic Build Command ----------------
# run NDK build
ndk-build.cmd \
-d \
-B \
NDK_DEBUG=1 \
NDK_PROJECT_PATH=C:/Path/BrowserPlugin/jni \
NDK_APPLICATION_MK=C:/Path/BrowserPlugin/jni/Application.mk \
NDK_MODULE_PATH=C:/Path/BrowserPlugin/jni \
NDK_APP_OUT=C:/Path/BrowserPlugin/jni/Out/ \
APP_BUILD_SCRIPT=C:/Path/BrowserPlugin/jni/Android.mk \
APP_OPTIM=$OPTIM
cp C:/Path/BrowserPlugin/jni/Out/local/armeabi/libsampleplugin.so C:/Path/BrowserPlugin/libs/armeabi/.
echo "copied libsampleplugin.so into PROJECT_ROOT/libs dir"
Android.mk:
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_SRC_FILES := \
main.cpp \
PluginObject.cpp \
RenderingThread.cpp \
animation/AnimationPlugin.cpp \
animation/AnimationThread.cpp \
audio/AudioPlugin.cpp \
background/BackgroundPlugin.cpp \
form/FormPlugin.cpp \
navigation/NavigationPlugin.cpp \
paint/PaintPlugin.cpp \
video/VideoPlugin.cpp \
jni-bridge.cpp \
WEBCORE_PATH := C:/Path/AndroidBrowserPlugin/webkit/Source/WebCore
LOCAL_C_INCLUDES += \
$(JNI_H_INCLUDE) \
$(LOCAL_PATH) \
$(LOCAL_PATH)/animation \
$(LOCAL_PATH)/audio \
$(LOCAL_PATH)/background \
$(LOCAL_PATH)/form \
$(LOCAL_PATH)/navigation \
$(LOCAL_PATH)/paint \
$(LOCAL_PATH)/video \
$(WEBCORE_PATH)/bridge \
$(WEBCORE_PATH)/plugins \
C:/Path/AndroidBrowserPlugin/webkit/Source/WebKit/android/JavaVM \
C:/Path/AndroidBrowserPlugin/webkit/Source/WebKit/android/plugins \
C:/Path/AndroidBrowserPlugin/platform_external_skia/include/core \
C:/Path/AndroidBrowserPlugin/frameworks_native/include \
C:/Path/AndroidBrowserPlugin/frameworks_native/libs \
C:/Path/AndroidBrowserPlugin/frameworks_native/opengl/libs \
C:/Path/AndroidBrowserPlugin/platform_system_core/include \
C:/Path/AndroidBrowserPlugin/frameworks_native/opengl/include \
C:/Users/user/android-ndk-r8c/platforms/android-14/arch-arm/usr/include \
C:/Path/AndroidBrowserPlugin/BrowserPlugin/jni/libs/armeabi \
C:/Path/AndroidBrowserPlugin/platform_bionic \
C:/Path/AndroidBrowserPlugin/platform_bionic/libc/private \
C:/Path/AndroidBrowserPlugin/platform_hardware_libhardware/include
SO_LIB_PATH := C:/Path/AndroidBrowserPlugin/libs_qualcomm_MDP8960
LOCAL_LDLIBS := \
-L$(SO_LIB_PATH)/ -lnativehelper -landroid -lutils -lcutils -lEGL -lGLESv2 -lskia
LOCAL_CFLAGS += -fvisibility=hidden
LOCAL_CFLAGS += -DHAVE_PTHREADS -DANDROID
LOCAL_MODULE:= libsampleplugin
LOCAL_MODULE_TAGS := optional
include $(BUILD_SHARED_LIBRARY)
Application.mk:
# =============================================================================
#
# Main build file defining the project modules and their global variables.
#
# =============================================================================
# Don't remove this - mandatory
APP_PROJECT_PATH := $(call my-dir)
# The only STL implementation currently working with exceptions
APP_STL := gnustl_static
# Don't optimize for better debugging
APP_OPTIM := debug
You may also need some header files (e.g. JNIHelp.h) which you can place e.g. in the root where you are doing the ndk build BrowserPlugin/jni/.
Hopefully bash build.sh should build your libsampleplugin.so which the build script copies into the app directory. You can then e.g. import the project into eclipse and build the app. Install it on the device, then e.g. use WAMP server to host the following file:
index.html:
<!DOCTYPE html>
<html>
<head>
<title>Test Plugin</title>
</head>
<body>
<object type="application/x-testbrowserplugin" height=50 width=250 id="testPlugin">
<param name="DrawingModel" value="Bitmap" />
<param name="PluginType" value="Form" />
</object>
</body>
</html>
run ipconfig from your host machine to get the IP address e.g. 192.168.x.x
Then point your device browser to e.g. http://192.168.x.x/ and voila you should see a form plugin.
I couldn't get the animation plugins to work properly, and the form plugin didn't work fully, but at least the plugin was recognised and loaded ok.
Now, you can write a webkit NPAPI plugin to do what you like either using the sample plugin browser as a guide, or other internet resources.
This is actually quite interesting topic which was discussed recently during blackhat 2014 (FakeID) but in a bit different context. They've found security bug in signature validation.
In your case there are two helpful links :
1) http://androidxref.com/4.3_r2.1/xref/frameworks/base/tests/BrowserTestPlugin/ This is the newest sample of writing webkit plugins. Try to build it - it will require to have webkit external statically linked otherwise you will get ‘ fatal error: android_npapi.h: No such file or directory’
2) http://androidxref.com/2.2.3/xref/development/samples/BrowserPlugin/ This is older sample but it has wider description of "how to build" browser plugin
Use combination of both link to start your plugin development
However this doesn't solve signature check problem. Even if the plugin is recognised it won't be allowed to run. I'm not sure what is the process with google to do browser plugin development

Categories

Resources