# This file is automatically generated by Android Tools.
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
#
# This file must be checked in Version Control Systems.
#
# To customize properties used by the Ant build system edit
# "ant.properties", and override values to adapt the script to your
# project structure.
#
# To enable ProGuard to shrink and obfuscate your code, unComment this (available properties: sdk.dir, user.home):
proGuard.config=${sdk.dir}/tools/ProGuard/ProGuard-android.txt:proGuard-project.txt
# Project target.
target=android-18
this is my project.properties file
# To enable ProGuard in your project, edit project.properties
# to define the proguard.config property as described in that file.
#
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in ${sdk.dir}/tools/proGuard/proGuard-android.txt
# You can edit the include path and order by changing the ProGuard
# include property in project.properties.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# Add any project specific keep options here:
# If your project uses WebView with JS, unComment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepClassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
this is my proguard-project.txt
I am enabling proguard like this when I try to build apk in release mode I am getting error code 1 in eclipse Juno. if I use same code in android studio I can able to build release apk . if I reverse engineer the apk which got from android studio I can read the entire code so how I can obfuscate the code
to work with proguard you need to just enable proguard using gradil script .
open gradil file and enable minifiable true and try to sign your application
Related
When trying to build a signed APK, it fails with ~100 lines repeating:
Library/Android/sdk/ndk-bundle/toolchains/arm-linux-androideabi-4.9/prebuilt/darwin-x86_64/lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin/ld: error: PLT offset too large, try linking with --long-plt
I've added --long-plt to the arguments:
externalNativeBuild {
cmake {
...
arguments '-DANDROID_STL=c++_static', '-Wl,--long-plt'
cppFlags "-frtti -fexceptions", "-DANDROID_TOOLCHAIN=clang", "-DANDROID_STL=c++_shared"
}
}
But it doesn't seem to change anything.
It works with non-signed (debug) apk generation and works with arm64-v8a.
I'm dealing with >1GB of native code, so I'm guessing that's the main reason.
It seems there is almost no documentation or search result regarding this.
Does --long-plt need to be put somewhere else? If not, is there another setting that can be changed? Or would splitting the code into separate libraries help?
Here's the CMakeLists.txt for reference:
string(REPLACE "." "/" JAVA_GEN_SUBDIR ${JAVA_GEN_PACKAGE})
set(JAVA_GEN_DIR ${Project_SOURCE_DIR}/src/main/java/${JAVA_GEN_SUBDIR}/../../../../../generated)
# configure import libs
set(distribution_DIR ${PROJECT_SOURCE_DIR}/distribution)
# Sets the minimum version of CMake required to build the native library.
cmake_minimum_required(VERSION 3.4.1)
# Note: One could use a 'GLOB' here, but newly added source files won't auto-regen build files
# After adding files, you'd need to 'touch' the CMakeLists.txt to re-gen
# SWIG required for build. Easy install is "brew install swig"
#Site: http://swig.org
find_package(SWIG REQUIRED)
include(${SWIG_USE_FILE})
# Remove old java files, in case we don't need to generate some of them anymore
#file(REMOVE_RECURSE ${JAVA_GEN_DIR})
# Ensure file recognized as C++ (otherwise, exported as C file)
set_property(SOURCE src/main/cpp/${LIBRARY_NAME}.i PROPERTY CPLUSPLUS ON)
# Setup SWIG flags and locations
set(CMAKE_SWIG_FLAGS -c++ -package ${JAVA_GEN_PACKAGE})
set(CMAKE_SWIG_OUTDIR ${JAVA_GEN_DIR})
# Export a wrapper file to Java, and link with the created C++ library
swig_add_module(${LIBRARY_NAME}_Wrapper java ${SWIG_I_FILE})
swig_link_libraries(${LIBRARY_NAME}_Wrapper ${LIBRARY_NAME})
# Include a location to the header files
include_directories(
src/main/cpp
${NativeLibPath}
${LUAPATH}
)
set(LUAPATH ${NativeLibPath}/lua)
file(GLOB ALL_SOURCE_FILES
"src/main/cpp/*.cpp"
"${NativeLibPath}/*.cpp"
"${LUAPATH}/*.c"
)
# Creates and names a library, sets it as either STATIC
# or SHARED, and provides the relative paths to its source code.
# You can define multiple libraries, and CMake builds them for you.
# Gradle automatically packages shared libraries with your APK.
add_library( # Sets the name of the library.
${LIBRARY_NAME}
# Sets the library as a shared library.
SHARED
# Provides the list of files to compile.
${ALL_SOURCE_FILES} )
target_include_directories(${LIBRARY_NAME} PRIVATE)
# Searches for a specified prebuilt library and stores the path as a
# variable. Because CMake includes system libraries in the search path by
# default, you only need to specify the name of the public NDK library
# you want to add. CMake verifies that the library exists before
# completing its build.
find_library( # Sets the name of the path variable.
log-lib
# Specifies the name of the NDK library that
# you want CMake to locate.
log )
# Specifies libraries CMake should link to your target library. You
# can link multiple libraries, such as libraries you define in this
# build script, prebuilt third-party libraries, or system libraries.
target_link_libraries(
# Specifies the target library.
${LIBRARY_NAME}
android
# Links the target library to the log library
# included in the NDK.
${log-lib}
)
I agree there is not so much documentation on internet, even if we can find some.
First, try to modify your configuration file:
externalNativeBuild {
cmake {
...
arguments '-DANDROID_STL=c++_static'
cppFlags "-frtti -fexceptions", "-DANDROID_TOOLCHAIN=clang", "-DANDROID_STL=c++_shared", "-Wl,--long-plt"
}
}
Let me know, if it changes anything?
while exporting signed application package in android application from eclipse, i am getting the error proguard returned with error code 1 :see console
here is my project.property file
# This file is automatically generated by Android Tools.
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
#
# This file must be checked in Version Control Systems.
#
# To customize properties used by the Ant build system edit
# "ant.properties", and override values to adapt the script to your
# project structure.
#
# To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
# Project target.
target=android-19
android.library.reference.1=../google-play-services_lib
android.library.reference.2=../ratinglibrary
android.library.reference.3=../appcompat_v7
android.library.reference.4=../ViewpagerLibrary
please anyone suggest me. Thanks in advance...
# Path to your oh-my-zsh installation.
export ZSH=/Users/baby/.oh-my-zsh
# Set name of the theme to load.
# Look in ~/.oh-my-zsh/themes/
# Optionally, if you set this to "random", it'll load a random theme each
# time that oh-my-zsh is loaded.
ZSH_THEME="robbyrussell"
#PATH to my android
export ANDROID_HOME=/Users/baby/ADT/android-sdk-macosx
export PATH=${PATH}:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools
# Uncomment the following line to use case-sensitive completion.
# CASE_SENSITIVE="true"
# Uncomment the following line to use hyphen-insensitive completion. Case
# sensitive completion must be off. _ and - will be interchangeable.
# HYPHEN_INSENSITIVE="true"
# Uncomment the following line to disable bi-weekly auto-update checks.
# DISABLE_AUTO_UPDATE="true"
# Uncomment the following line to change how often to auto-update (in days).
# export UPDATE_ZSH_DAYS=13
# Uncomment the following line to disable colors in ls.
# DISABLE_LS_COLORS="true"
# Uncomment the following line to disable auto-setting terminal title.
# DISABLE_AUTO_TITLE="true"
# Uncomment the following line to enable command auto-correction.
# ENABLE_CORRECTION="true"
# Uncomment the following line to display red dots whilst waiting for completion.
# COMPLETION_WAITING_DOTS="true"
# Uncomment the following line if you want to disable marking untracked files
# under VCS as dirty. This makes repository status check for large repositories
# much, much faster.
# DISABLE_UNTRACKED_FILES_DIRTY="true"
# Uncomment the following line if you want to change the command execution time
# stamp shown in the history command output.
# The optional three formats: "mm/dd/yyyy"|"dd.mm.yyyy"|"yyyy-mm-dd"
# HIST_STAMPS="mm/dd/yyyy"
# Would you like to use another custom folder than $ZSH/custom?
# ZSH_CUSTOM=/path/to/new-custom-folder
# Which plugins would you like to load? (plugins can be found in ~/.oh-my-zsh/plugins/*)
# Custom plugins may be added to ~/.oh-my-zsh/custom/plugins/
# Example format: plugins=(rails git textmate ruby lighthouse)
# Add wisely, as too many plugins slow down shell startup.
plugins=(git)
# User configuration
export PATH="/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"
# export MANPATH="/usr/local/man:$MANPATH"
source $ZSH/oh-my-zsh.sh
# You may need to manually set your language environment
# export LANG=en_US.UTF-8
# Preferred editor for local and remote sessions
# if [[ -n $SSH_CONNECTION ]]; then
# export EDITOR='vim'
# else
# export EDITOR='mvim'
# fi
# Compilation flags
# export ARCHFLAGS="-arch x86_64"
# ssh
# export SSH_KEY_PATH="~/.ssh/dsa_id"
# Set personal aliases, overriding those provided by oh-my-zsh libs,
# plugins, and themes. Aliases can be placed here, though oh-my-zsh
# users are encouraged to define aliases within the ZSH_CUSTOM folder.
# For a full list of active aliases, run `alias`.
#
# Example aliases
# alias zshconfig="mate ~/.zshrc"
# alias ohmyzsh="mate ~/.oh-my-zsh"
Why does my $PATH show this?
zsh:no such file or
directory:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
I use zsh and I have added this in .zshrc:
export ANDROID_HOME=/Users/baby/ADT/android-sdk-macosx
export PATH=${PATH}:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools
How should my environment variables be set in zsh to use Android SDK in OSX EL Capitan?
I have the following in my .zshrc file
export ANDROID_HOME=/usr/local/opt/android-sdk
path=("${ANDROID_HOME}/platform-tools:${ANDROID_HOME}/tools" $path)
The value of ANDROID_HOME will depend on your personal setup. I used Homebrew - The missing package manager for OS X to install the android-sdk:
brew install android-sdk
See also: Adding a new entry to the PATH variable in ZSH
Here's what I had to list in my .zshrc:
export ANDROID_HOME=~/Library/Android/sdk
export ANDROID_SDK_ROOT=$ANDROID_HOME
export PATH=$PATH:$ANDROID_HOME/tools:$ANDROID_HOME/tools/bin:$ANDROID_HOME/platform-tools
I needed to add ANDROID_SDK_ROOT for legacy support in my project.
I have problem with proguard, I have tried with many possible solutions but still does not solve my problem.
The only information I get from console is
Proguard returned with error code 1. See console
nothing more, this is a really bad error message I ever met.
I have set
proguard.config=proguard-project.txt
and nothing in proguard-project.txt that I believe only a couple of comments.
# To enable ProGuard in your project, edit project.properties
# to define the proguard.config property as described in that file.
#
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in ${sdk.dir}/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the ProGuard
# include property in project.properties.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# Add any project specific keep options here:
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
# This is a configuration file for ProGuard.
# http://proguard.sourceforge.net/index.html#manual/usage.html
After couples of hours finding the solution, I found the solution. I just moved the proguard.jar to another directory which there is no space in the path, then I edited the proguard.bat in /bin folder to that directory. Eventually, the proguard is running fine and give me the error log that I expected.
Sample script.
#ECHO OFF
REM Start-up script for ProGuard -- free class file shrinker, optimizer,
REM obfuscator, and preverifier for Java bytecode.
rem Change current directory and drive to where the script is, to avoid
rem issues with directories containing whitespaces.
cd /d %~dp0
IF EXIST "%PROGUARD_HOME%" GOTO home
SET PROGUARD_HOME=..
:home
java -jar C:\bin\proguard.jar %*
You have commented text file, it should be like this :
# To enable ProGuard in your project, edit project.properties
# to define the proguard.config property as described in that file.
#
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in ${sdk.dir}/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the ProGuard
# include property in project.properties.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# Add any project specific keep options here:
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
-keepclassmembers class fqcn.of.javascript.interface.for.webview {
public *;
}
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-verbose
# Optimization is turned off by default. Dex does not like code run
# through the ProGuard optimize and preverify steps (and performs some
# of these optimizations on its own).
-dontoptimize
-dontpreverify
# Note that if you want to enable optimization, you cannot just
# include optimization flags in your own project configuration file;
# instead you will need to point to the
# "proguard-android-optimize.txt" file instead of this one from your
# project.properties file.
-keepattributes *Annotation*
-keep public class com.google.vending.licensing.ILicensingService
-keep public class com.android.vending.licensing.ILicensingService
# For native methods, see http://proguard.sourceforge.net/manual/examples.html#native
-keepclasseswithmembernames class * {
native <methods>;
}
# keep setters in Views so that animations can still work.
# see http://proguard.sourceforge.net/manual/examples.html#beans
-keepclassmembers public class * extends android.view.View {
void set*(***);
*** get*();
}
# We want to keep methods in Activity that could be used in the XML attribute onClick
-keepclassmembers class * extends android.app.Activity {
public void *(android.view.View);
}
# For enumeration classes, see http://proguard.sourceforge.net/manual/examples.html#enumerations
-keepclassmembers enum * {
public static **[] values();
public static ** valueOf(java.lang.String);
}
-keep class * implements android.os.Parcelable {
public static final android.os.Parcelable$Creator *;
}
-keepclassmembers class **.R$* {
public static <fields>;
}
# The support library contains references to newer platform versions.
# Don't warn about those in case this app is linking against an older
# platform version. We know about them, and they are safe.
-dontwarn android.support.**
Build using following commands:
cd <you project directory>
#update project properties
android update project -t 3 -p .
#clean the code
ant clean
# build the application
ant release
i try to optimize my Android Application code using Proguard with eclipse ADT v21.1.0-569685 on MAC.
i used project->Android Tools->export asigned Application package option for signing with my private certificate,on finish of signing i got following error,
project.properties
# This file is automatically generated by Android Tools.
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
#
# This file must be checked in Version Control Systems.
#
# To customize properties used by the Ant build system edit
# "ant.properties", and override values to adapt the script to your
# project structure.
#
# To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
# Project target.
target=android-17
android.library.reference.1=../google-play-services_lib
proguard-project.txt
# To enable ProGuard in your project, edit project.properties
# to define the proguard.config property as described in that file.
#
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in ${sdk.dir}/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the ProGuard
# include property in project.properties.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# Add any project specific keep options here:
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
Console Log:
[2013-04-12 10:41:53 - MyApp] Proguard returned with error code 1. See console
[2013-04-12 10:41:53 - MyApp] proguard.ParseException: Expecting class member name before '#' in line 82 of file '/Users/MyOrg/Android_workspace/MyApp/bin/proguard.txt',
[2013-04-12 10:41:53 - MyApp] included from argument number 6
[2013-04-12 10:41:53 - MyApp] at proguard.ConfigurationParser.readNextWord(ConfigurationParser.java:1133)
[2013-04-12 10:41:53 - MyApp] at proguard.ConfigurationParser.readNextWord(ConfigurationParser.java:1117)
[2013-04-12 10:41:53 - MyApp] at proguard.ConfigurationParser.parseMemberSpecificationArguments(ConfigurationParser.java:845)
[2013-04-12 10:41:53 - MyApp] at proguard.ConfigurationParser.parseClassSpecificationArguments(ConfigurationParser.java:697)
[2013-04-12 10:41:53 - MyApp] at proguard.ConfigurationParser.parseKeepClassSpecificationArguments(ConfigurationParser.java:490)
[2013-04-12 10:41:53 - MyApp] at proguard.ConfigurationParser.parse(ConfigurationParser.java:139)
[2013-04-12 10:41:53 - MyApp] at proguard.ProGuard.main(ProGuard.java:484)
How to solve the above issue?
In prouard.project file I read
If your project uses WebView with JS, uncomment the following and
specify the fully qualified class name to the JavaScript interface
class:
I have used webview in two activity with WebAppInterface.java class.How to do above statement?
Referring resource name like "#string/on_click_handler_name", in android:onClick attribute of your layout file is ok. However, proguard cannot resolve these references.
Check http://android.okhelp.cz/proguard-parseexception-expecting-class-member-name-before/ for more details.
Find corresponding value of #string/tha_lf_et_todate_onclick in your string.xml and update :
android:onClick="#string/tha_lf_et_todate_onclick"
to
android:onClick="onClickXXX"
in your layout file.
For the second question,
uncomment that piece of code, and replace "fqcn.of.javascript.interface.for.webview"
with the class's fully qualified name.