Android 'debuggable' default value - android

I am trying to get application's debuggable attribute value from code:
packageInfo = context.getPackageManager().getPackageInfo(packageName, 0);
int flags = packageInfo.applicationInfo.flags;
isDebugMode = (flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0;
And I have noticed that when debuggable attribute is not specified in manifest this code defines it as true. And documentation says that it is false by default.
What's wrong?

From SDK Tools : ( SDK Tools, Revision 8 (December 2010) )
Support for a true debug build.
Developers no longer need to add the
android:debuggable attribute to the
<application> tag in the manifest —
the build tools add the attribute automatically. In Eclipse/ADT, all
incremental builds are assumed to be
debug builds, so the tools insert
android:debuggable="true". When
exporting a signed release build,
the tools do not add the attribute.
In Ant, a ant debug command
automatically inserts the
android:debuggable="true" attribute,
while ant release does not. If android:debuggable="true" is manually
set, then ant release will actually do
a debug build, rather than a release
build.

Related

what is modules tagged with user in AOSP build system

I am trying to understand the android file system.
May I know what will happen with the AOSP compilation with "user" mode?
1.Installs modules tagged with the user.
What does this mean? What is the end behavior because of this?
2. Set the property ro.debuggable=0, turn off the application debugging function​
What does this mean? User can not debug an application?
Thank you.
For 1, see the doc about build-variants, and have a look at What is the use of LOCAL_MODULE_TAGS?
For 2, see the comments about ro.debuggable:
/**
* Returns true if the device is running a debuggable build such as "userdebug" or "eng".
*
* Debuggable builds allow users to gain root access via local shell, attach debuggers to any
* application regardless of whether they have the "debuggable" attribute set, or downgrade
* selinux into "permissive" mode in particular.
* #hide
*/
#UnsupportedAppUsage
public static final boolean IS_DEBUGGABLE =
SystemProperties.getInt("ro.debuggable", 0) == 1;
For userdebug build, all application are debuggable, and for user build, only application with debuggable build variant can be debuggable. You can build debuggable build variant application by setting android:debuggable to true in AndroidManifest.xml

How to assign manifestPlaceholders ONLY to the instrumentation APK

I have a placeholder in my AAR's manifest. The AAR builds with no problem when I use assembleRelease/assembleDebug, but when I run my Android instrumentation tests, gradle fails to build the instrumentation APK and throws an error that looks like this
Attribute <blah-blah>#<xyz> at manifestMerger....xml requires a placeholder substitution but no value for <my-place-holder> is provided.
Just for testing purposes (and to confirm whether I can set the value of a placehoder for a specific build type), I set the placeholder value in the debug build type with this:
android { ... buildTypes { debug { manifestPlaceholders = [my-place-holder:"my-value"]
It worked (the release version keeps the placehoder and the placeholder was replaced in the debug version). However, I don't want to (and actually should not) do this because that means my debug version will override the placeholder in the AAR's manifest but I must keep the placeholder in the manifest so it can be overridden by the users of my AAR.
Does anybody knows how to assign manifestPlaceholders ONLY to the instrumentation APK?

ndk-build stays at NDEBUG=1 despite Gradle debuggable: true in Android Studio

I'm having a ton of difficulty trying to get Gradle to compile a debug version of my JNI code through NDK build. I've set the debug build to be debuggable in the build.gradle file like so:
buildTypes {
debug {
debuggable true
jniDebuggable true
}
}
I can confirm that the switches are taking effect if I check out Build/Edit Build types. However, once I check the ndkBuild_build_command.txt file inside of the .externalNdkBuild directory, I notice the following entries:
NDEBUG=1
APP_PLATFORM=android-9
I can confirm that my JNI code does not seem to be debuggable. Even though the breakpoints trigger, variables all show "variable not available" in LLVM.
Any ideas as to why NDEBUG is turned on even in a debug build? As a sidenote, I also have no idea where the android-9 platform is entering in... I'm not setting that myself anywhere that I could find.
If you use Android Studio 2.2 with externalNativeBuild, you can set APP_OPTIM=debug in your Application.mk or NDK_DEBUG=1 through parameters override, e.g.
externalNativeBuild {
ndkBuild {
arguments "NDK_DEBUG:=1"
}
}

Does zipalign execute automatically when a .apk is generated as signed from Android Studio?

I am wondering if the method of generating a signed .apk for release , also zipaligns the apk . In the directions of the android page (http://developer.android.com/tools/publishing/app-signing.html#studio) , it is not clear if zipalign is a different step.
thank you!
You can define build types in the build.gradle file.
buildTypes {
debug {
storeFile file("debug.keystore")
}
release {
zipAlignEnabled true
}
}
The debug config is used when you are debugging your apk and the release config when you're creating a release apk.
If you set zipAlignEnabled true in case of release, the apk will be zipaligned. If you do not specify it, the default value is true in case of release and the apk will be zipaligned automatically. For debug, the default value is false.
Read more about build types and other possible properties you can set here : http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Build-Types
The Android build tools can handle this for you. Android Studio automatically aligns your APK.
use the below command to confirm the alignment of existing.apk:
zipalign -c -v <alignment> existing.apk
The is an integer that defines the byte-alignment boundaries. This must always be 4 (which provides 32-bit alignment) or else it effectively does nothing.
Flags:
-f : overwrite existing outfile.zip
-v : verbose output
-p : outfile.zip should use the same page alignment for all shared object files within infile.zip
-c : confirm the alignment of the given file
Zipalign

If debugable is set to false or true it changes nothing

I have Android debuggable set to false, yet the condition true. What is wrong here?
Application:
//debugable false or true, nothing changes
if ((applicationFlags & ApplicationInfo.FLAG_DEBUGGABLE) != 0) {
Log.d(TAG, "debugable");
}
Manifest:
<application android:debuggable="false" ...
The answer to this very question is already given on SO.
See Android 'debuggable' default value.
.
Declaring your application as "debuggable" in your Android Manifest enables you to debug your Android applications on an Android-powered device , just as you would on the emulator
When using Eclipse, running your app directly from the Eclipse IDE automatically enables debugging.
If you manually enable debugging in the manifest file, be sure to disable it before you build for release (your published application should usually not be debuggable).
The debuggable flag in the manifest gets changed automatically, you can remove it completely, which is also recommended by Google.
If you debug your application, the flag is true. If you export the applicaton, the flag is false.

Categories

Resources