Example apps with data not working

also to debug it, add a ofLogNotice() << ofToDataPath(""); to your setup and check the logcat to see which path it’s pointing too. and you can see if the files are there using any file explorer and checking the sdcard, the data should be in /sdcard/cc.openframeworks.appName/

OK thanks, I haven’t tried develop yet. Basically it has to be some path issue I think, however no errors were produced in the process so it was rather mysterious.

Hi Arturo, is this still true? I’m trying to run the ofxPd addon example on android and after a bit of work have it launching successfully but erroring out during creation of the directory on the sdcard. The pd patch I’d like to run won’t load because copying it over during installation fails as below:

03-08 13:00:33.965: E/OF(627): error creating dir /mnt/sdcard/Android/data/cc.openframeworks.androidofxPdExample
03-08 13:00:33.965: E/OF(627): java.lang.Exception

The reason is that this code @ line 159 in OFAndroid.java is throwing an exception because mkdir() fails.

  
 if(!dir.exists() && dir.mkdir()!=true)   
	throw new Exception();  

upon further research, I’ve added

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

to my manifest.xml … No luck.

I’m officially out of ideas? Any thoughts gentlemen? I get the same results on a Galaxy Nexus, as I do on the emulator.

My setup/toolchain is:
ofx 0.7.4 android release, ndkr8d, MacOSX 10.7.5, latest ADT from Google

cheers,
d

the problem should be with the permission, we removed it by accident for 0.7.0 i’ve also found some days ago a problem with how the data path is being detected for some devices. in OFAndroid you need to change getRealExternalStorage to:

  
  
public static String getRealExternalStorageDirectory()  
	{				  
		// Standard way to get the external storage directory  
		String externalPath = Environment.getExternalStorageDirectory().getAbsolutePath();	  
		File SDCardDir = new File(externalPath);		  
    	if(SDCardDir.exists() && SDCardDir.canWrite()) {		  
    		return externalPath;  
    	}  
		  
		// This checks if any of the directories from mExternalStorageDirectories exist, if it does, it uses that one instead  
		for(int i = 0; i < mExternalStorageDirectories.length; i++)  
		{  
			//Log.i("OF", "Checking: " + mExternalStorageDirectories[i]);	  
			SDCardDir = new File(mExternalStorageDirectories[i]);		  
	    	if(SDCardDir.exists() && SDCardDir.canWrite()) {				  
	    		externalPath = mExternalStorageDirectories[i];	// Found writable location  
				break;  
	    	}	    	  
		}  
		  
		Log.i("OF", "Using storage location: " + externalPath);  
		return externalPath;		  
	}  
  

Thanks again Arturo, I got past this error now on my Galaxy Nexus (only) and can see all my data via adb shell!

Unfortunately the emulator is still not working. I read a lot about adding command line arguments “-sdcard” to the emulator launch command (or invoke emu directly it from the terminal) to get around the /mnt/sdcard showing d—rwxrwx (as we see in the DDMS explorer view) For now, I focus on a real device :slight_smile:

Back to debugging my pd-patch loading and the sound of silence!! This ofxPd addon test on Android is proving to be quite involved.

Arturo, do you have any hints on debugging the NDK (stepping through it in gdb/eclipse) or have other pearls of wisdom?

cheers,
d

Hi guys! I’ve just encountered a problem related to data on Android device: my app runs without trouble with oF0.8.0, and I can see all datas in the right folder on the Android device.
If I try to use the master from github instead everything compiles fine, but no data is seen! The app obviously crashes, then I check on the device and the data folder is empty; I’ve already checked the path in the log from the app and it’s correct…

do you have some ideas/suggestions, please? is there something different in the actual master that I have to know about data management?

Thanks!

ofCinzio, does the problem happen on the emulator or on a real device? I don’t think it would happen on a real device.

Hello! thank you for joining the discussion!

I’m on a real device (a Samsung Galaxy Tab 2);
I’ve tried also to run some examples (perfectly working with the stable 0.8.0) with the latest version of oF taken from github, and the same thing happens: apps with data always crash, because data folder on the device is empty! :frowning:

Did you try to create the directory manually by a file browser before launching your app? If so what happens? Can you create it? And can the app be launched then?

Another thing, altough I don’t believe that it is your problem; are you sure the name of your xxxresources.zip file contains only lower case letters? I remember Android doesn’t accept file names with upper cases under /res folder.

ps. You can try also the directory name with only lower case letters.

Thank you again for your help!

I tried manually copying the data folder (generated on the device with a 0.8.0-equivalent app compiled), but with no luck; also tried to lower-case everything… still same errors…

Then I tried all the android examples included with the master, and I can confirm that only the ones without data worked; any of the other can’t find resources (and their data folders are actually empty) and gave me the usual errors in the log cat (“couldn’t find file…” etc…)

it’s really strange… oF0.8.0 worked out of the box for me, without any trouble… but I want to switch to the github master branch in order to make the camera working (and also to take advantage from some other useful fixes…)

can you post the output of logcat? i did some changes to the way we find out the app’s data folder, it’s working for me but perhaps it’s problematic in other devices

thanks, Arturo!

ok! I just ran “androidImageExample” on my Galaxy Tab 2.0 (Android 4.2.1); the app starts but displays no image (data folder on the device is empty) here’s the output from the logcat:

01-10 13:03:55.772: D/dalvikvm(5121): Trying to load lib /data/data/cc.openframeworks.androidImageExample/lib/libneondetection.so 0x414b2978
01-10 13:03:55.772: D/dalvikvm(5121): Added shared lib /data/data/cc.openframeworks.androidImageExample/lib/libneondetection.so 0x414b2978
01-10 13:03:55.772: D/dalvikvm(5121): No JNI_OnLoad found in /data/data/cc.openframeworks.androidImageExample/lib/libneondetection.so 0x414b2978, skipping init
01-10 13:03:55.772: I/OF(5121): loading neon optimized library
01-10 13:03:55.772: D/dalvikvm(5121): Trying to load lib /data/data/cc.openframeworks.androidImageExample/lib/libOFAndroidApp_neon.so 0x414b2978
01-10 13:03:55.795: I/VoiceImeLanguageUpdaterImpl(5103): #internalUpdateLanguages #77
01-10 13:03:55.881: D/dalvikvm(5121): Added shared lib /data/data/cc.openframeworks.androidImageExample/lib/libOFAndroidApp_neon.so 0x414b2978
01-10 13:03:55.881: I/(5121): JNI_OnLoad called
01-10 13:03:55.881: I/OF(5121): initializing app
01-10 13:03:55.881: I/OF(5121): OFAndorid init...
01-10 13:03:55.889: I/OF(5121): starting resources extractor
01-10 13:03:55.897: I/OF(5121): joining
01-10 13:03:55.936: I/ActivityThread(5144): Pub com.google.android.partnersetup.rlzprovider: com.google.android.partnersetup.RlzProvider
01-10 13:03:55.936: I/ActivityThread(5144): Pub com.google.android.partnersetup.rlzappprovider: com.google.android.partnersetup.RlzAppProvider
01-10 13:03:55.952: I/OF(5121): sd mounted: true
01-10 13:03:55.952: I/OF(5121): creating app directory: /storage/sdcard0/Android/data/cc.openframeworks.androidImageExample
01-10 13:03:55.960: I/ofAppAndroidWindow(5121): setting app dir name to: "/storage/sdcard0/Android/data/cc.openframeworks.androidImageExample"
01-10 13:03:55.960: I/OF(5121): app name: androidImageExample
01-10 13:03:55.960: I/OF(5121): checking /androidimageexampleresources.zip
01-10 13:03:55.960: I/OF(5121): joined
01-10 13:03:55.991: V/OF(5121): trying to find class: cc.openframeworks.androidImageExample.R$layout
01-10 13:03:56.006: D/KeyguardViewMediator(322): setHidden false
01-10 13:03:56.014: D/dalvikvm(5103): GC_CONCURRENT freed 297K, 11% free 7923K/8839K, paused 17ms+8ms, total 60ms
01-10 13:03:56.022: I/OF(5121): onResume
01-10 13:03:56.022: D/KeyguardViewMediator(322): setHidden false
01-10 13:03:56.030: D/KeyguardViewMediator(322): setHidden false
01-10 13:03:56.038: E/WindowStateAnimator(322): createSurfaceLocked called attrs.flags=25231616
01-10 13:03:56.038: D/STATUSBAR-StatusBarManagerService(322): setSystemUiVisibility(0x0)
01-10 13:03:56.038: D/STATUSBAR-StatusBarManagerService(322): manageDisableList what=0x0 pkg=WindowManager.LayoutParams
01-10 13:03:56.045: D/KeyguardViewMediator(322): setHidden false
01-10 13:03:56.053: D/libEGL(5121): loaded /vendor/lib/egl/libEGL_POWERVR_SGX540_120.so
01-10 13:03:56.061: D/libEGL(5121): loaded /vendor/lib/egl/libGLESv1_CM_POWERVR_SGX540_120.so
01-10 13:03:56.069: D/libEGL(5121): loaded /vendor/lib/egl/libGLESv2_POWERVR_SGX540_120.so
01-10 13:03:56.139: D/OpenGLRenderer(5121): Enabling debug mode 0
01-10 13:03:56.147: V/AT_Distributor(111): received[idx : 4, fd : 11] : FactoryClientRecv, 0
01-10 13:03:56.147: D/AT_Distributor(111): SocketRemove() : 11
01-10 13:03:56.147: D/AT_Distributor(111): close client fd
01-10 13:03:56.147: V/AT_Distributor(111): received[idx : 5, fd : 12] : FactoryClientSend, 0
01-10 13:03:56.147: D/AT_Distributor(111): SocketRemove() : 12
01-10 13:03:56.147: D/AT_Distributor(111): close client fd
01-10 13:03:56.155: D/KeyguardViewMediator(322): setHidden false
01-10 13:03:56.155: E/WindowStateAnimator(322): createSurfaceLocked called attrs.flags=16920
01-10 13:03:56.178: D/dalvikvm(5165): GC_CONCURRENT freed 153K, 9% free 7710K/8455K, paused 18ms+2ms, total 63ms
01-10 13:03:56.178: D/dalvikvm(5165): WAIT_FOR_CONCURRENT_GC blocked 33ms
01-10 13:03:56.327: I/OF(5121): onSurfaceCreated
01-10 13:03:56.327: I/ofAppAndroidWindow(5121): setup
01-10 13:03:56.327: E/ofImage(5121): loadImage(): couldn't load image from "images/bikers.jpg"
01-10 13:03:56.327: I/ofAppAndroidWindow(5121): resize 600x895
01-10 13:03:56.335: W/ofGLRenderer(5121): drawing an unallocated texture
01-10 13:03:56.366: D/KeyguardViewMediator(322): setHidden false
01-10 13:03:56.366: W/ofGLRenderer(5121): drawing an unallocated texture
01-10 13:03:56.374: I/ClipboardServiceEx(322): Send intent for dismiss clipboard dialog inside hideCurrentInputLocked() !
01-10 13:03:56.381: I/power(322): *** release_dvfs_lock : lockType : 1 
01-10 13:03:56.381: D/KeyguardViewMediator(322): setHidden false
01-10 13:03:56.381: D/Finsky(5165): [1] FinskyApp.onCreate: Initializing network with DFE https://android.clients.google.com/fdfe/
01-10 13:03:56.381: D/PowerManagerService(322): releaseDVFSLockLocked : all DVFS_MIN_LIMIT are released 
01-10 13:03:56.381: W/ActivityManager(322): mDVFSLock.release()
01-10 13:03:56.389: D/KeyguardViewMediator(322): setHidden false
01-10 13:03:56.397: W/ofGLRenderer(5121): drawing an unallocated texture
01-10 13:03:56.405: W/ofGLRenderer(5121): drawing an unallocated texture
01-10 13:03:56.420: W/ofGLRenderer(5121): drawing an unallocated texture
01-10 13:03:56.428: W/ofGLRenderer(5121): drawing an unallocated texture

and so on…

thank you again for you interest!

are you checking this folder?

/storage/sdcard0/Android/data/cc.openframeworks.androidImageExample

that’s what the app is trying to use, weirdly i get

/storage/sdcard0/Android/data/cc.openframeworks.androidImageExample/files

with the new method.

also can you check if you have res/raw/androidimageexampleresources.zip
in your project after running the app?

on the device I found this folder empty:
/storage/sdcard0/Android/data/cc.openframeworks.androidImageExample

and there’s no “files” subfolder…

after running the app the zip resource file is inside res/raw/ (I tried to decompress it and I found all the images that were in the data folder)

can you pull again from master? seems like the app name that should been converted to lower case to get the name of the resources file is not being converted properly, i’ve done a small change to see if that fixes it. if it still doesn’t work please post the output from logcat again

ok! thank you!I’ll let you know as soon as I’ve downloaded the new master!

great!

simply copy-pasted the 3 lines you’ve modified in OFAndroid.java and now the examples work!
I’ve just tried 4 different examples that use data and no one gave me problems! the data folder is now on the device in the right position!

thank you so much!

Hii

Is there any update on this? I also had the same problem so I pulled the new openframeworks from git, but still no luck. Other examples like Polygon work fine on my device, but the imageExample doesn’.

Edit: resolved!
As Arturo suggested, I added ofLogNotice() << ofToDataPath("") to see the path and finally resolved it by adding ‘bin/data’ to the path:

image.loadImage("bin/data/images/bikers.jpg");

Hi poorya7 i have issues with all android examples with external resources in the bin/data directory.
On compile, this is how the console looks like:

11:39:20 **** Incremental Build of configuration Debug for project androidImageExample ****
make -j4 Debug PLATFORM_OS=Android 
HOST_OS=MINGW32_NT-6.2
HOST_ARCH=i686
Compiling OF library for Debug
make -C /d/of_v0.9.0_android_release/libs/openFrameworksCompiled/project/ Debug PLATFORM_OS=Android ABIS_TO_COMPILE_DEBUG="armv7"
HOST_OS=MINGW32_NT-6.2
HOST_ARCH=i686
make[1]: Entering directory `/d/of_v0.9.0_android_release/libs/openFrameworksCompiled/project'
HOST_OS=MINGW32_NT-6.2
HOST_ARCH=i686

HOST_OS=MINGW32_NT-6.2
HOST_ARCH=i686
Done!
make[1]: Leaving directory `/d/of_v0.9.0_android_release/libs/openFrameworksCompiled/project'


Compiling androidImageExample for Debug
HOST_OS=MINGW32_NT-6.2
HOST_ARCH=i686
make[1]: Entering directory `/d/of_v0.9.0_android_release/examples/android/androidImageExample'
make[1]: Leaving directory `/d/of_v0.9.0_android_release/examples/android/androidImageExample'

HOST_OS=MINGW32_NT-6.2
HOST_ARCH=i686
make[1]: Entering directory `/d/of_v0.9.0_android_release/examples/android/androidImageExample'
compressing and copying resources from bin/data into res
cd "/d/of_v0.9.0_android_release/examples/android/androidImageExample"; \
	if [ -d "bin/data" ]; then \
		mkdir -p res/raw; \
		rm res/raw/ofdataresources.zip; \
		cd bin/data; \
		if [ "windows-x86_64" = "windows" ]; then \
			echo "Windows Platform. Running Zip..."; \
			cmd //c ..\\..\\..\\..\\..\\libs\\openFrameworksCompiled\\project\\android\\windows\\zip -r ../../res/raw/ofdataresources.zip * && exit; \
		else \
			zip -r ../../res/raw/ofdataresources.zip *; \
		fi; \
		cd ../..; \
	fi
rm: cannot lstat `res/raw/ofdataresources.zip': No such file or directory
/bin/sh: line 9: zip: command not found
copying debugging binaries for armv7
create gdb.setup for armeabi-v7a
creating Android.mk and Application.mk
#@echo updating ofAndroidLib project
#@cd /d/of_v0.9.0_android_release/addons/ofxAndroid/ofAndroidLib; \
	#if [ "windows-x86_64" = "windows" ]; then \
	#	cmd //c D:/Android/tools/android.bat update project --target android-21 --path .; \
	#else \
	#	D:/Android/tools/android update project --target android-21 --path .; \
	#fi
#@echo updating current project
#@cd /d/of_v0.9.0_android_release/examples/android/androidImageExample; \
	#if [ "windows-x86_64" = "windows" ]; then \
	#	cmd //c D:/Android/tools/android.bat update project --target android-21 --path .; \
	#else \
	#	D:/Android/tools/android update project --target android-21 --path .; \
	#fi
make[1]: Leaving directory `/d/of_v0.9.0_android_release/examples/android/androidImageExample'

11:40:31 Build Finished (took 1m:11s.760ms)

and this is how the “problems” tab

I am running on windows 10, OF version 0.9.0 and ndk r10e

Thanks in advance.