Does source code are included with the APK taken from Android studio?
if yes how can we remove it so that users can't access the source code anytime
Source code is not added into APK, but bytecode of APK can be decoded into java code.
You can use proguard to shrink, obfuscate, and optimize your app and it's hard to read when decoded.
Here are example of using proguard (put it into build.gradle)
android {
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'),
'proguard-rules.pro'
}
}
}
Related
In Android Studio, when I click the "debug" icon in the tool bar, gradle is appearing to try to make a release build.
First, it shows me the "edit configuration" popup. At the bottom, it has a message "the apk for your currently selected variant (app-release-unsigned.apk) is not signed. Please specify a signing configuration for this variant (release).
Why is it trying to use "release" when I click "debug"? Obviously I changed something, I wish I knew what...
Here's my app build.gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 24
buildToolsVersion "25.0.0"
compileOptions.encoding = 'UTF-8'
defaultConfig {
applicationId "com.perinote.camera"
minSdkVersion 15
targetSdkVersion 24
renderscriptTargetApi 20
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
lintOptions {
checkReleaseBuilds false
}
}
dependencies {
compile 'com.android.support:support-v4:24.0.0'
testCompile 'junit:junit:4.12'
}
Solved by deleting the .idea directory. After it was regenerated, my builds were correctly produced.
I also completely removed and reinstalled Android Studio and the SDK. However, the debug build was still messed up after that.
I use gradle's experimental plugin in order to add some NDK code.
before usage of NDK support my buildTypes section was next
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
as you can see here I use optimized options of ProGuard.
And when I started to use gradle's experimental plugin I changed those lines to
buildTypes {
release {
minifyEnabled true
proguardFiles.add(file('proguard-rules.pro'))
}
}
The question is next: is it ok to use such options when I want to use 'proguard-android-optimize.txt' file?
If not then how I could define that I want to use 'proguard-android-optimize.txt' file with gradle's experimental plugin?
I came across this issue recently, and found that Gradle Experimental doesn't appear to include any version of ProGuard config by default, and there's no "getDefaultProguardFile()" method to call.
I've had to resort to adding the 'proguard-android-optimize.txt' file to my project for now (and referencing it in my build.gradle), as my project won't build without at least the basic rules being specified.
I'm using Gradle Experimental 0.7.2.
I change my ProGuard configuration depending upon the gradle build type. I do this so that I can magically disable certain code when creating a release build.
Example builds:
buildTypes {
debug {
minifyEnabled true
proguardFiles 'proguard-debug.cfg'
}
release {
minifyEnabled true
proguardFiles 'proguard.cfg'
}
}
Android Studio is content to add the proguard.cfg file to my Project View, but not the proguard-debug.cfg file.
Example Project View from my project (it shows my proguard config and from a library module, but not from my debug config).
Structure of the directory:
project
-- .gradle
-- .idea
-- app (module)
-- -- src
-- -- Other files / folders
-- -- proguard-debug.cfg
-- -- proguard.cfg
-- -- proguard-release.cfg
-- Other files / folders
-- build.gradle
-- settings.gradle
I imported several eclipse projects to Android Studio (v1.1).
In the original Eclipse environment, they use Proguard for release mode.
In the Android Studio environment, this was translated to the following in the build.gradle script (by the import, not by me):
buildTypes {
release {
minifyEnabled true
proguardFiles 'proguard.cfg'
}
}
I understand that this means that "in release build, enable Proguard's minify, using proguard.cfg".
The problem, however, is that minify seems to be happening in non-release build (i.e. debug) as well!
How is this possible?
What is the default for minifyEnabled for debug build?
UPDATE 1: Thanks to the answer below, I now know that the default is false. Which means something else is building the various modules minified in debug build.
I am posting the entire build.gradle for one of the modules that get minified in debug build:
apply plugin: 'com.android.library'
android {
compileSdkVersion 8
buildToolsVersion "21.1.2"
defaultConfig {
minSdkVersion 8
targetSdkVersion 8
}
buildTypes {
release {
minifyEnabled true
proguardFiles 'proguard.cfg'
}
}
}
The entire build.gradle for the project itself (i.e. top level) is:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.1.0'
}
}
allprojects {
repositories {
jcenter()
}
}
I cannot spot here anything that could explain enforcing minify on a debug build.
UPDATE 2: Suspecting a mismatch between app's build (debug) and the modules on which it depends (release?), I also checked the Build Variant view on the the left panel. The all show debug unequivocally.
UPDATE 3: It appears that I hit a bug/limitation in Android-Gradle?
I truly need all modules built in debug mode when the app is built in debug mode.
Any ideas how I can solve this problem?
The default value for minifyEnabled is false for all build types, as #laalto answered.
However, currently (as of 2015-04-24), this is not true for multi-module projects, in which some modules (app included) are dependent on other modules. This is due to bug #52962 that causes build types to not propagate to libraries -- they're always built as RELEASE.
Suggestions to work around this bug or notifications of its fix are most welcome.
What is the default for minifyEnabled for debug build?
The default value for minifyEnabled is false for all build types. Reference.
The problem, however, is that minify seems to be happening in non-release build (i.e. debug) as well!
How is this possible?
Your debug build gets proguard treatment possibly by some other definition somewhere, or an external build script you're using.
In your updated question, you have a library project and an app project that uses a minified library even for debug builds. That's a "feature". For a solution, consider the following also mentioned in the issue report:
Build all variants of the library project by adding the following to its build.gradle:
android {
publishNonDefault true
}
In the app project, choose the build type specific dependency with
dependencies {
releaseCompile project(path: ':theotherproject', configuration: 'release')
debugCompile project(path: ':theotherproject', configuration: 'debug')
}
I am using Android Studio 1.1.0 to build an APK for internal distribution in my company using AirWatch.
My understanding of how to build an APK is to go to the "Build==>Make Project". However, when I do that AS does not generate an APK. However, if I go to "Run==>Run App" then I do get an APK.
I fear I have something misconfigured in AS, as this is my first project.
Bryan
There are two.
Here is the first.
apply plugin: 'com.android.application'
android {
signingConfigs {
config {
keyAlias 'XXXXXXXXXXXXXXX'
keyPassword 'password'
storeFile file('PATH')
storePassword 'XXXXXX'
}
}
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "com.ACME.application"
minSdkVersion 15
targetSdkVersion 21
versionCode 1
versionName "1.0.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.config
}
debug{
debuggable true
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile files('libs/commons-lang-2.3.jar')
compile 'com.android.support:appcompat-v7:21.0.3'
compile 'com.android.support:support-v4:21.0.3'
compile 'com.google.android.gms:play-services:6.5.87'
compile files('src/main/assets/library-1.0.10.jar')
}
Here is the second.
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.0.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
Seems like you are getting correct behavior from Android Studio.
You are correct that to build an APK, you can go to the "Build==>Make Project". When you "build" the project, you are just creating the APK, not installing it on any device or emulator. So you won't see your app 'running' anywhere after this step. Selecting this item in the GUI is the same as running the command line gradle build.
The APK is placed in this directory:
<Your root project folder>/<app name>/build/outputs/apk
You can then install this APK on a device using the command line, or by dragging and dropping the file onto an emulator.
When you go to "Run==>Run App" then you also get an APK. But you get even more! This apk is not only built, it is installed onto your connected device / emulator automatically for you. Selecting this item in the GUI is the same as running the two commands gradle build and adb install.