<uses-sdk android:minSdkVersion="7" />
我开始为结果活动的所有片段都能正确地获得结果.
有一天(在我更新到SDK 20之前)我正在修复lint问题,并且我根据lint标志的请求将manifest:targetSdkVersion添加到清单中,我很快意识到我的所有片段都没有接收到他们的onActivityResilt()调用.
现在每次我更新到SDK 20.0.1后,我都被迫在清单中的uses-sdk条目中使用android:targetSdkVersion;否则R.java永远不会生成.
这是我当前的uses-sdk清单条目
<uses-sdk android:minSdkVersion="7" android:targetSdkVersion="16" />
目前由于这个奇怪的错误,我的应用程序目前仍然被打破.
我试过更新我的兼容库最新版本r9.
此外,我已经仔细检查了片段中的所有startActivityForResult()调用.他们都通过片段的方法使用正确的调用.
即
this.startActivityForResult(intent,requestCode);
不
this.getActivity().startActivityForResult(intent,requestCode);
我目前的开发环境:
Android SDK 20.0.1 Android SDK Platform Tools 13 ADT 20.0.2
任何帮助将不胜感激,因为这个bug目前是阻止我最终beta测试的砖墙.
编辑
这是我的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
编辑
我查看了/app/android-sdk-linux_86/tools/ant/build.xml:616,发现以下行抛出了null enabled =“${manifestmerger.enabled}”>
这是整个街区
我将尝试禁用清单合并选项,看看会发生什么
编辑
似乎从project.properties中删除manifestmerger.enabled = true已经解决了我的问题.该项目现在编译并完美运行.我想我应该把这个bug报告给android团队.我的清单有以下条目
<uses-sdk android:minSdkVersion="7" />
但是如果我将targetSdkVersion提高到7以上仍然没有调用onActivityResult(),所以这并没有真正解决root问题,但我的项目现在正常工作
解决方法
getActivty().startActivityForResult(intent,requestCode); // Cannot receive in fragment
在Fragment中(正确的startActivityForResult)
startActivityForResult(intent,requestCode); // use Fragment.startActivityForRusult() // not Activity.startActivityForRusult()
在活动中
@Override protected void onActivityResult(int requestCode,int resultCode,Intent data) { super.onActivityResult(requestCode,resultCode,data); }
在片段中
@Override protected void onActivityResult(int requestCode,Intent data) { // Do Action }