Remove Debug Code For Release Build
2012-09-12 15:51
369 查看
From: http://mobiledevelopertips.com/debugging/remove-debug-code-for-release-build.html
When it’s time to remove debug code and log messasges from your application, it’s straight forward if you follow a few simple steps during development.
First, wrap debugging code in a block similar to the following:
From the Edit Scheme dialog select the Run tab. In the Info tab, set the Build Configuration to Debug. By the way, when you create a new project, Debug is the default value, so you can skip this step if you have not previously changed the value.
When you are ready to have the debug code removed from your build,
return to the Edit Scheme menu and set the Build Configuration to
Release. When you rebuild the project, the code inside the #ifdef DEBUG –
#endif will no longer be included in the app.
You can see the preprocessing macro definitions that make this possible by opening the Build Settings and searching for debug. You will find the DEBUG macro defined as follows:
Removing Console / NSLog Messages
In a previous post, Debugging Macros,
I wrote an alternative for NSLog. Along with this, I included code to
turn those same messages off. However, there is now a much cleaner way
to do this using the DEBUG preprocessor macro shown above:
You can now write debugging messages to the console as follows, which will be removed when creating a release build:
When it’s time to remove debug code and log messasges from your application, it’s straight forward if you follow a few simple steps during development.
First, wrap debugging code in a block similar to the following:
#ifdef DEBUG // Debug code here... #endif
From the Edit Scheme dialog select the Run tab. In the Info tab, set the Build Configuration to Debug. By the way, when you create a new project, Debug is the default value, so you can skip this step if you have not previously changed the value.
When you are ready to have the debug code removed from your build,
return to the Edit Scheme menu and set the Build Configuration to
Release. When you rebuild the project, the code inside the #ifdef DEBUG –
#endif will no longer be included in the app.
You can see the preprocessing macro definitions that make this possible by opening the Build Settings and searching for debug. You will find the DEBUG macro defined as follows:
Removing Console / NSLog Messages
In a previous post, Debugging Macros,
I wrote an alternative for NSLog. Along with this, I included code to
turn those same messages off. However, there is now a much cleaner way
to do this using the DEBUG preprocessor macro shown above:
#ifdef DEBUG #define debug(format, ...) CFShow([NSString stringWithFormat:format, ## __VA_ARGS__]); #else #define debug(format, ...) #endif
You can now write debugging messages to the console as follows, which will be removed when creating a release build:
debug(@"Your debug message here...");
相关文章推荐
- Linking different libraries for Debug and Release builds in Cmake on windows?
- Linking different libraries for Debug and Release builds in Cmake on windows?
- Atlas Control Toolkit and Source Code for the Build-in Asp.Net 2.0 Providers
- iOS "directory not found for option '-L/Users/.../Pods/build/Debug-iphoneos"解决方案
- Error:Execution failed for task ':app:transformClassesWithJarMergingForRelease'. > com.android.build
- AS出现Error:Execution failed for task ':app:buildInfoDebugLoader'.解决办法
- Error:Execution failed for task ':app:transformClassesWithDexForDebug'. > com.android.build.api.tran
- 异常:Error:Execution failed for task ':Seeyou:transformClassesWithDexForDebug'. > com.android.build.ap
- Error:Execution failed for task ':app:transformClassesWithDexForDebug'. > com.android.build.api.tran
- ':app:transformClassesWithDexForDebug'. > com.android.build.transform.api.TransformException: when i
- Error:Execution failed for task ':app:transformClassesWithDexForDebug'. > com.Android.build.api.tra
- Error:Execution failed for task ':app:buildInfoDebugLoader'. > Exception while doing past iteration
- android studio 出现Error:Execution failed for task ':app:buildInfoDebugLoader'.的解决办法
- Caffe编译出现:Makefile:603: recipe for target '.build_release/lib/libcaffe-nv.so.0.16.6' failed
- Error:Execution failed for task ':app:buildInfoDebugLoader'. 解决方法
- Execution failed for task ':app:buildInfoDebugLoader'
- 关于android studio 出现Error:Execution failed for task ':app:buildInfoDebugLoader'.的解决办法
- Execution failed for task ':app:preDebugAndroidTestBuild
- Android Studio在build的时候出现transformClassesWithDexForDebug
- Error:Execution failed for task ':app:transformClassesWithDexForAnzhiRelease'. > com.android.build.a