6

I have been working on an application for android that utilizes the android comparability library (android-support-v4). Before SDK 20, I was able to compile my application with the following uses-sdk entry in my manifest.

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

All my fragments that started an activity for result received their results properly.

One day (Before I updated to SDK 20) I was fixing lint issues, and I added android:targetSdkVersion to the manifest per the lint flag's request, and I soon realized that none of my fragments were receiving their onActivityResilt() calls.

Now every since I have updated to SDK 20.0.1, I am forced to utilize the android:targetSdkVersion in uses-sdk entry in my manifest; otherwise R.java is never generated.

Here is my current uses-sdk manifest entry

<uses-sdk
    android:minSdkVersion="7"
    android:targetSdkVersion="16" />

Currently because of this odd bug, my application is currently still broken. I have tryied updating my compatibly library the the latest version r9.

Also I have double checked all my startActivityForResult() calls in the fragments. They all use the proper calls through the fragment's method.

i.e.

 this.startActivityForResult(intent, requestCode);

not

 this.getActivity().startActivityForResult(intent, requestCode);

My current Development Environment:

Android SDK 20.0.1
Android SDK Platform Tools 13
ADT 20.0.2

Any help would be greatly appreciated, as this bug is currently the brick wall that is preventing my final beta tests.

EDIT

Here's my output of ant debug

$ ant debug Buildfile: /home/ricky/Development/workspace/location_ringer/LocationRinger/build.xml

-set-mode-check:

-set-debug-files:

-check-env: [checkenv] Android SDK Tools Revision 20.0.1 [checkenv] Installed at /app/android-sdk-linux_86

-setup: [echo] Project Name: ListActivity [gettype] Project Type: Application

-set-debug-mode:

-debug-obfuscation-check:

-build-setup: [echo] Resolving Build Target for ListActivity... [gettarget] Project Target: Google APIs [gettarget] Vendor: Google Inc. [gettarget] Platform Version: 4.1 [gettarget] API level:
16 [echo] ---------- [echo] Creating output directories if needed... [echo] ---------- [echo] Resolving Dependencies for ListActivity... [dependency] Library dependencies: [dependency] [dependency] ------------------ [dependency] Ordered libraries: [dependency] [dependency] ------------------ [dependency] API<=15: Adding annotations.jar to the classpath. [echo] ---------- [echo] Building Libraries with 'debug'...

nodeps:

-set-mode-check:

-set-debug-files:

-check-env: [checkenv] Android SDK Tools Revision 20.0.1 [checkenv] Installed at /app/android-sdk-linux_86

-setup: [echo] Project Name: LocationLib [gettype] Project Type: Android Library

-set-debug-mode:

-debug-obfuscation-check:

-build-setup: [echo] Resolving Build Target for LocationLib... [gettarget] Project Target: Google APIs [gettarget] Vendor: Google Inc. [gettarget] Platform Version: 4.1 [gettarget] API level:
16 [echo] ---------- [echo] Creating output directories if needed... [echo] ---------- [echo] Resolving Dependencies for LocationLib... [dependency] Library dependencies: [dependency] No Libraries [dependency] [dependency] ------------------ [dependency] API<=15: Adding annotations.jar to the classpath.

-pre-build:

-code-gen: [mergemanifest] No changes in the AndroidManifest files. [echo] Handling aidl files... [aidl] No AIDL files to compile. [echo] ---------- [echo] Handling RenderScript files... [renderscript] No RenderScript files to compile. [echo] ---------- [echo] Handling Resources... [aapt] No changed resources. R.java and Manifest.java untouched. [echo] ---------- [echo] Handling BuildConfig class... [buildconfig] No need to generate new BuildConfig.

-pre-compile:

-compile: [echo] Creating library output jar file...

-post-compile:

-obfuscate:

-dex: [echo] Library project: do not convert bytecode...

-crunch: [crunch] Crunching PNG Files in source dir: /home/ricky/Development/workspace/location_library/LocationLib/res
[crunch] To destination dir: /home/ricky/Development/workspace/location_library/LocationLib/bin/res [crunch] Crunched 0 PNG files to update cache

-package-resources: [echo] Library project: do not package resources...

-package: [echo] Library project: do not package apk...

-post-package:

-do-debug: [echo] Library project: do not create apk... [propertyfile] Updating property file: /home/ricky/Development/workspace/location_library/LocationLib/bin/build.prop [propertyfile] Updating property file: /home/ricky/Development/workspace/location_library/LocationLib/bin/build.prop [propertyfile] Updating property file: /home/ricky/Development/workspace/location_library/LocationLib/bin/build.prop [propertyfile] Updating property file: /home/ricky/Development/workspace/location_library/LocationLib/bin/build.prop

-post-build:

debug:

nodeps:

-set-mode-check:

-set-debug-files:

-check-env: [checkenv] Android SDK Tools Revision 20.0.1 [checkenv] Installed at /app/android-sdk-linux_86

-setup: [echo] Project Name: ExceptionHandlerLib [gettype] Project Type: Android Library

-set-debug-mode:

-debug-obfuscation-check:

-build-setup: [echo] Resolving Build Target for ExceptionHandlerLib... [gettarget] Project Target: Android 4.1 [gettarget] API level:
16 [echo] ---------- [echo] Creating output directories if needed... [echo] ---------- [echo] Resolving Dependencies for ExceptionHandlerLib... [dependency] Library dependencies: [dependency] No Libraries [dependency] [dependency] ------------------ [dependency] API<=15: Adding annotations.jar to the classpath.

-pre-build:

-code-gen: [mergemanifest] No changes in the AndroidManifest files. [echo] Handling aidl files... [aidl] No AIDL files to compile. [echo] ---------- [echo] Handling RenderScript files... [renderscript] No RenderScript files to compile. [echo] ---------- [echo] Handling Resources... [aapt] No changed resources. R.java and Manifest.java untouched. [echo] ---------- [echo] Handling BuildConfig class... [buildconfig] No need to generate new BuildConfig.

-pre-compile:

-compile: [echo] Creating library output jar file...

-post-compile:

-obfuscate:

-dex: [echo] Library project: do not convert bytecode...

-crunch: [crunch] Crunching PNG Files in source dir: /home/ricky/Development/workspace/exception_handler_library/ExceptionHandlerLib/res [crunch] To destination dir: /home/ricky/Development/workspace/exception_handler_library/ExceptionHandlerLib/bin/res [crunch] Crunched 0 PNG files to update cache

-package-resources: [echo] Library project: do not package resources...

-package: [echo] Library project: do not package apk...

-post-package:

-do-debug: [echo] Library project: do not create apk... [propertyfile] Updating property file: /home/ricky/Development/workspace/exception_handler_library/ExceptionHandlerLib/bin/build.prop [propertyfile] Updating property file: /home/ricky/Development/workspace/exception_handler_library/ExceptionHandlerLib/bin/build.prop [propertyfile] Updating property file: /home/ricky/Development/workspace/exception_handler_library/ExceptionHandlerLib/bin/build.prop [propertyfile] Updating property file: /home/ricky/Development/workspace/exception_handler_library/ExceptionHandlerLib/bin/build.prop

-post-build:

debug:

-pre-build:

-code-gen: [mergemanifest] Merging AndroidManifest files into one. [mergemanifest] Merging manifests from project and 2 libraries. [mergemanifest] Warning: [AndroidManifest.xml:3, AndroidManifest.xml:3] Main manifest has but library uses targetSdkVersion='16' [mergemanifest] Note: main manifest lacks a declaration, which defaults to value minSdkVersion or 1. [mergemanifest] Warning: [AndroidManifest.xml:3, AndroidManifest.xml:13] Main manifest has but library uses targetSdkVersion='16' [mergemanifest] Note: main manifest lacks a declaration, which defaults to value minSdkVersion or 1.

BUILD FAILED /app/android-sdk-linux_86/tools/ant/build.xml:616: null

Total time: 2 seconds

EDIT

I looked into /app/android-sdk-linux_86/tools/ant/build.xml:616 and found that the following line threw the null enabled="${manifestmerger.enabled}">

here is the entire block

I am going to try to disable the manifest merger option an see what happens

EDIT

It would seem that removing manifestmerger.enabled=true from project.properties has solved my problem. The project now compiles and works perfectly. I think I should report this bug to the android team. My manifest has the following entry

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

However onActivityResult() still isn't called if I raise the targetSdkVersion higher than 7, so this doesn't really solve the root problem, but my project is now working properly

Cœur
  • 37,241
  • 25
  • 195
  • 267
Rick Barrette
  • 272
  • 4
  • 19
  • Which version of the support library are you using? v9 fixes some bugs apparent with `onActivityResult(..)`. – Alex Curran Aug 01 '12 at 18:10
  • I'm using android-support-v4 r9 – Rick Barrette Aug 01 '12 at 18:28
  • Have you tried with `android:targetSdkVersion="7"`? – pawelzieba Aug 01 '12 at 19:59
  • Try with android:minSdkVersion="8" – Pointer Null Aug 01 '12 at 20:31
  • I have, but when I change the target version to anything other than 16, my project doesn't compile. I have also tried setting the minSdkVersion to 8 but with no success – Rick Barrette Aug 01 '12 at 22:15
  • I got 2 questions: Have you rechecked your imports, are they pointing to the right classes in compability lib? and 2nd: which Sdk platforms do you have installed and are they up to date? – Ostkontentitan Aug 03 '12 at 15:04
  • If you are calling like this.startActivityForResult(intent, requestCode);from fragment and you have also override method OnActivityResult in the parent of fragment then result will be recieved on parent onActivityResult method. for that you should call like this getActivity().startActivityForResult(intent, requestCode); – Krishna Shrestha Aug 06 '12 at 06:14
  • The parent FragmentActivity does not override onActivityResult() – Rick Barrette Aug 06 '12 at 14:57

5 Answers5

7

In Fragment (Wrong startActivityForResult)

getActivty().startActivityForResult(intent, requestCode); 
// Cannot receive in fragment

In Fragment (Correct startActivityForResult)

startActivityForResult(intent, requestCode); 
// use Fragment.startActivityForRusult()
// not Activity.startActivityForRusult()

In activity

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
}

In Fragment

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    // Do Action
}
ChangUZ
  • 5,380
  • 10
  • 46
  • 64
2

Here's a couple of suggestions:

  • If you just want to be able to not have android:targetSdkVersion in your manifest, you should be able to right-click your project in the Project Explorer in Eclipse and select Android Tools > Clear Lint Markers.

  • Check to make sure that all your Fragment and Activity-derived classes extends the correct classes from the compatibility library (android.support.v4.app.Fragment and android.support.v4.app.FragmentActivity) and none are accidentally extending the ones in the framework (android.app.Fragment and android.app.Activity).

Also, I find it strange that your project doesn't compile if you set your targetSdkVersion to anything other than 16. Is there any specific issue indicated in the Problems/Console/Lint window? Please also check whether you have other target available and/or selected as Project Build Target (right-click project, Properties > Android).

Joe
  • 14,039
  • 2
  • 39
  • 49
  • I have already double checked to make sure that my application is using android.support.v4.app.*. Also I have tried removing `targetSdkVersion` and clearing the lint markers with no success. – Rick Barrette Aug 06 '12 at 14:40
  • My build target under **Properties > Android** is set to 16. I also find it strange that R.java is not generated if I set the `targetSdkVersion` lower to 16. I am currently trying to build using different API levels. – Rick Barrette Aug 06 '12 at 14:55
  • The thing that is really odd is that there is no error message for why R.java is not being generated. As for my above comment, I have had no luck with changing the api build target under **Properties > Android** – Rick Barrette Aug 06 '12 at 15:07
  • 1
    That is odd. I wonder if you want to try and see if building from the command line will give any error message. If you haven't tried it before, usually you just need to go to your project folder on a command prompt and run `android update project -p .` (to initialize the local.properties and build.xml files) and then `ant debug` (to make the build). – Joe Aug 06 '12 at 15:27
  • I updated the question with the out put, I am going to look into android-sdk-linux_86/tools/ant/build.xml:616 – Rick Barrette Aug 06 '12 at 16:14
  • It would seem that removing `manifestmerger.enabled=true` from project.properties has solved my problem. The project now compiles and works perfectly. I think I should report this bug to the android team. My manifest has the following entry – Rick Barrette Aug 06 '12 at 16:30
  • Joseph, please write an answer with our work, and I will select it as the accepted answer. Thanks again for all the help – Rick Barrette Aug 06 '12 at 16:31
  • Sorry, my manifest entry was really `` – Rick Barrette Aug 06 '12 at 16:38
  • onActivityResult() still isn't called if I raise the `targetSdkVersion ` higher than 7, so this doesn't really solve the root problem, but my project is now working properly. – Rick Barrette Aug 06 '12 at 16:58
  • Glad to help! I felt undeserving of the accepted answer though, since as you mentioned, we still see the onActivityResult() not getting called if we modify the `targetSdkVersion` value. Maybe for now you can just vote up my answer (or the comment regarding building with ant) since at least it is helpful. If I figure out the real problem with targetSdkVersion and onActivityResult(), I will definitely post it as a separate answer here. – Joe Aug 06 '12 at 17:58
0

There's a bug in the compatibility pack (see this and this)

Maria Neumayer
  • 3,337
  • 3
  • 27
  • 44
  • I am aware of that bug, but it was fixed by time r9 came out. I already checked to make sure onActivityResult() wasn't called in the fragment activity – Rick Barrette Aug 05 '12 at 13:36
0

After downloading the latest ADT make sure you also overwrite your support jar in your project with this one:

android-sdk\extras\android\support\v4\android-support-v4.jar

It's possible your using an old jar while running the latest ADT.

Otherwise I would only expect your Fragments to not receive their onActivityResult() calls if the parent Activity wasn't calling super.onActivityResult(requestCode, resultCode, data);

EDIT

Explicitly adding this was necessary for my project:

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    Fragment fragment = getSupportFragmentManager().findFragmentById(R.id.dualPane);
    fragment.onActivityResult(requestCode, resultCode, data);
}
Graeme
  • 25,714
  • 24
  • 124
  • 186
  • yes I verified that I have the newest. this bug exist in both r7 and r9 – Rick Barrette Aug 08 '12 at 17:36
  • you said "when I change the target version to anything other than 16, my project doesn't compile." What problems are you getting when you reduce your target version? This means you're using higher level API's in your project than you think you are. – Graeme Aug 09 '12 at 08:13
0

It would seem that removing manifestmerger.enabled=true from project.properties has solved my problem. The project now compiles and works perfectly. I think I should report this bug to the android team. My manifest has the following entry

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

However onActivityResult() still isn't called if I raise the targetSdkVersion higher than 7, so this doesn't really solve the root problem, but my project is now working properly

Rick Barrette
  • 272
  • 4
  • 19