Android Studio and ProGuard - can't write resource [META-INF/MANIFEST.MF] (Duplicate zip entry [volley.jar:META-INF/MANIFEST.MF]) - actionbarsherlock

I have an Android app which uses actionbarsherlock and the next jars under the libs
folder:
android-support-v4.jar
gson-2.2.4.jar
libGoogleAnalyticsV2.jar
volley.jar
I am trying to generate a Signed APK with Android Studio Build#AI-130.692269. I check both checkboxes "Run ProGuard" and "Include system proguard file"
My ProGuard path file proguard-project.txt looks like:
# 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 *;
#}
I have edited project.properties which now looks like:
# 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
proguard.config=/Applications/adt-bundle-mac-x86_64/sdk/tools/proguard/proguard-android.txt:proguard-project.txt
# Project target.
target=android-17
android.library=false
android.library.reference.1=../AndroidBarSherlock/actionbarsherlock
This is the output I am getting:
Information:ProGuard: [SocialPrice] ProGuard, version 4.7
Information:ProGuard: [SocialPrice] Reading input...
Information:ProGuard: [SocialPrice] Reading program jar [/Users/sdelamo/Library/Caches/AndroidStudioPreview/compile-server/_temp_/proguard_input4364141808943557175.jar]
Information:ProGuard: [SocialPrice] Reading program jar [/Users/sdelamo/Documents/Developer/android/facebook-android-sdk-3.0.1/facebook/libs/android-support-v4.jar]
Information:ProGuard: [SocialPrice] Reading program jar [/Users/sdelamo/Documents/workspaceAndroid/SocialPrice/libs/volley.jar]
Information:ProGuard: [SocialPrice] Reading program jar [/Users/sdelamo/Documents/workspaceAndroid/SocialPrice/libs/libGoogleAnalyticsV2.jar]
Information:ProGuard: [SocialPrice] Reading program jar [/Users/sdelamo/Documents/workspaceAndroid/SocialPrice/libs/gson-2.2.4.jar]
Information:ProGuard: [SocialPrice] Reading library jar [/Applications/Android Studio.app/sdk/platforms/android-17/android.jar]
Information:ProGuard: [SocialPrice] Initializing...
Information:ProGuard: [SocialPrice] Note: com.google.analytics.tracking.android.AdHitIdGenerator: can't find dynamically referenced class com.google.ads.AdRequest
Information:ProGuard: [SocialPrice] Note: com.google.gson.internal.UnsafeAllocator: can't find dynamically referenced class sun.misc.Unsafe
Information:ProGuard: [SocialPrice] Note: the configuration refers to the unknown class 'com.google.vending.licensing.ILicensingService'
Information:ProGuard: [SocialPrice] Note: the configuration refers to the unknown class 'com.android.vending.licensing.ILicensingService'
Information:ProGuard: [SocialPrice] Note: there were 2 references to unknown classes.
Information:ProGuard: [SocialPrice] You should check your configuration for typos.
Information:ProGuard: [SocialPrice] Note: there were 2 unresolved dynamic references to classes or interfaces.
Information:ProGuard: [SocialPrice] Ignoring unused library classes...
Information:ProGuard: [SocialPrice] Original number of library classes: 3259
Information:ProGuard: [SocialPrice] Final number of library classes: 841
Information:ProGuard: [SocialPrice] Printing kept classes, fields, and methods...
Information:ProGuard: [SocialPrice] Shrinking...
Information:ProGuard: [SocialPrice] Printing usage to [/Users/sdelamo/Documents/workspaceAndroid/SocialPrice/proguard_logs/usage.txt]...
Information:ProGuard: [SocialPrice] Removing unused program classes and class elements...
Information:ProGuard: [SocialPrice] Original number of program classes: 921
Information:ProGuard: [SocialPrice] Final number of program classes: 579
Information:ProGuard: [SocialPrice] Obfuscating...
Information:ProGuard: [SocialPrice] Printing mapping to [/Users/sdelamo/Documents/workspaceAndroid/SocialPrice/proguard_logs/mapping.txt]...
Information:ProGuard: [SocialPrice] Writing output...
Information:ProGuard: [SocialPrice] Preparing output jar [/Users/sdelamo/Library/Caches/AndroidStudioPreview/compile-server/socialprice_a27782ee/android/intermediate_artifacts/SocialPrice/obfuscated_sources.jar]
Information:ProGuard: [SocialPrice] Copying resources from program jar [/Users/sdelamo/Library/Caches/AndroidStudioPreview/compile-server/_temp_/proguard_input4364141808943557175.jar]
Information:ProGuard: [SocialPrice] Copying resources from program jar [/Users/sdelamo/Documents/Developer/android/facebook-android-sdk-3.0.1/facebook/libs/android-support-v4.jar]
Information:ProGuard: [SocialPrice] Copying resources from program jar [/Users/sdelamo/Documents/workspaceAndroid/SocialPrice/libs/volley.jar]
Information:ProGuard: [SocialPrice] Copying resources from program jar [/Users/sdelamo/Documents/workspaceAndroid/SocialPrice/libs/libGoogleAnalyticsV2.jar]
Information:ProGuard: [SocialPrice] Copying resources from program jar [/Users/sdelamo/Documents/workspaceAndroid/SocialPrice/libs/gson-2.2.4.jar]
Information:ProGuard: [SocialPrice] Printing classes to [/Users/sdelamo/Documents/workspaceAndroid/SocialPrice/proguard_logs/dump.txt]...
Information:Compilation completed successfully with 4 warnings in 2 min 28 sec
Information:0 errors
Information:4 warnings
Warning:ProGuard: [SocialPrice] You should check if you need to specify additional program jars.
Warning:ProGuard: [SocialPrice] Warning: can't write resource [META-INF/MANIFEST.MF] (Duplicate zip entry [volley.jar:META-INF/MANIFEST.MF])
Warning:ProGuard: [SocialPrice] Warning: can't write resource [META-INF/MANIFEST.MF] (Duplicate zip entry [libGoogleAnalyticsV2.jar:META-INF/MANIFEST.MF])
Warning:ProGuard: [SocialPrice] Warning: can't write resource [META-INF/MANIFEST.MF] (Duplicate zip entry [gson-2.2.4.jar:META-INF/MANIFEST.MF])
I am completely new to ProGuard, so any feedback is welcome.

I came across a similar problem when trying to use joda-time library.
By adding
packagingOptions {
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
}
to the android section in build.gradle, the error was gone.
The solution was found in
Duplicate files copied (Android Studio 0.4.0)

A similar problem is reported in this url. Hope it helps.
BTW also make sure that you use the latest version of Android SDK.. it will create an empty proguard-project.txt for your project.

Since version 0.9.1 it is possible to include a file when there's a conflict during packaging:
android.packagingOptions {
pickFirst 'META-INF/MANIFEST.MF'
}
See Gradle release notes for further information.

add -dontwarn to proguard.cfg to ignore warnings

Related

CXX1405 cmake exception while building android project

Got error when I build the project like in the below. I tried so many things but never succeeded. I'm using m1 MacBook. Is this related with this error ?
[CXX1405] exception while building Json A problem occurred starting process 'command '/Users/serhat/Library/Android/sdk/cmake/3.18.1/bin/cmake''
in build.gradle:
externalNativeBuild {
cmake {
path "CMakeLists.txt"
}
}
and this is CmakeList.txt :
# For more information about using CMake with Android Studio,read the
# documentation: https://d.android.com/studio/projects/add-native-code.html
# Sets the minimum version of CMake required to build the native library.
cmake_minimum_required(VERSION 3.4.1)
# 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.
native-lib
# Sets the library as a shared library.
SHARED
# Provides a relative path to your source file(s).
src/main/cpp/native-lib.cpp )
# 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.
native-lib
# Links the target library to the log library
# included in the NDK.
${log-lib} )
I fixed this issue :
softwareupdate --install-rosetta

New header file not showed in Project Mode in Android Studio 3.1.1

I'm trying to learn a bit of Android development.
I've started a new project for a simple hello world and it works fine.
The project is essentially the default one + one more header file in the cpp folder,
However I can't see such .cpp in the project mode, can anyone suggest how to fix this?
(See picture below).
I've attempted to change some setting in File > Project Structure but it doesn't seem to make any difference.
Maybe worth noticing that the header file isn't listed in the CMakeLists.txt at all.
# For more information about using CMake with Android Studio, read the
# documentation: https://d.android.com/studio/projects/add-native-code.html
# Sets the minimum version of CMake required to build the native library.
cmake_minimum_required(VERSION 3.4.1)
# 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.
native-lib
# Sets the library as a shared library.
SHARED
# Provides a relative path to your source file(s).
src/main/cpp/native-lib.cpp )
# 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.
native-lib
# Links the target library to the log library
# included in the NDK.
${log-lib} )
According to the android doc:
Known Issue: Android Studio currently shows you only the header files that have matching source files—even if you specify other headers in your CMake build script. See Issue #38068472
This means you need a pair filename.h and filename.cpp, you modify your CMakeLists.txt accordingly. The header file will be shown in project mode if it has a corresponding .cpp with the same name.
Reference:
https://developer.android.com/studio/projects/add-native-code

cmake error while building OpenCV in native on Android Studio

I am trying to compile OpenCV in native on Android Studio. I am trying to follow : https://sriraghu.com/2017/03/11/opencv-in-android-an-introduction-part-1/
I was succesfully able to do it by following these steps on Windows. However on Ubuntu, its not working. The error is :
Execution failed for task ‘:app:externalNativeBuildDebug’.
Build command failed. Error while executing process /home/user/Android/Sdk/cmake/3.6.4111459/bin/cmake with arguments {–build
/home/user/AndroidStudioProjects/project_folders/app/.externalNativeBuild/cmake/debug/arm64-v8a
–target native-lib}
ninja: error: ‘../../../../jniLibs/src/main/jniLibs/arm64-v8a/libopencv_java3.so’,
needed by
‘../../../../build/intermediates/cmake/debug/obj/arm64-v8a/libnative-lib.so’,
missing and no known rule to make it
The CMakeLists.txt file is:
cmake_minimum_required(VERSION 3.4.1)
set(pathToOpenCV /media/user/Stuff/Softwares/OpenCV-android-sdk/sdk/native)
include_directories(${pathToOpenCV}/jni/include)
add_library( # Sets the name of the library.
native-lib
# Sets the library as a shared library.
SHARED
# Provides a relative path to your source file(s).
src/main/cpp/native-lib.cpp )
# 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.
add_library(lib_opencv SHARED IMPORTED)
set_target_properties(lib_opencv PROPERTIES IMPORTED_LOCATIONS /home/user/cmu/android-apps/OpenCV_app_June23/OpenCV_Android/app/src/main/jniLibs/arm64-v8a/libopencv_java3.so)
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.
native-lib
# Links the target library to the log library
# included in the NDK.
${log-lib} lib_opencv)
In native-lib.cpp, I am able to add #include without any error prompts in Android Studio.
My previous searches suggest that there is something wrong with the paths. I have checked that the paths are correct, or is there a different way to put the path in Ubuntu?

META-INF manifest is discarded on ducplication

[info] Merging files...
[warn] Merging 'META-INF\INDEX.LIST' with strategy 'discard'
[warn] Merging 'META-INF\MANIFEST.MF' with strategy 'discard'
I'm trying to use sbt-assembly to assemble a project. I already have a jar file in my project that has META-INF folder and MANIFEST.MF file! sbt-assembly very smartly opt to discard conflict MANIFEST which is of course very nice. However, I don't want other people to use -classpath and have to type in main class each time, so I want to add my own MANIFEST.MF file and tell sbt-assembly to generate a right one.
How can I do that?? Thank you!!
I don't want other people to use -classpath and have to type in main class each time
Here's from the readme:
To set an explicit main class,
mainClass in assembly := Some("com.example.Main")

Ant LibusbJava compile error: "jni.h: No such file"...fixed, now a memset error

There appears to be a Ant / jni.h problem (for my setup) with LibusbJava. I get the following error when setting up LibusbJava by running
ant linux
in CentOS 6.3 as root (quick and dirty test, thanks for those concerned about user level =0). I will redo with proper restrictions as shown on a libusbjava reference after reflection when first install works. LibusbJava, is a Java wrapper for the libusb library.
The output starts out like this:
[root#somebox LibusbJava]# ant linux -lib $JAVA_HOME/include -lib $JAVA_HOME/include/linux
Buildfile: build.xml
clean:
Build LibusbJava Test Linux:
Build LibusbJava Test:
[echo] Building Library for unit tests:
[exec] /.../libusbjava/trunk/LibusbJava/LibusbJava.cpp:27:17: error: jni.h: No such file or directory
[exec] /.../libusbjava/trunk/LibusbJava/LibusbJava.cpp:34:26: error: test/CuTest.h: No such file or directory
`...`
as it was not set on my system. It appears that jni.h is a header called by C++ code, which I had to add to the LibusbJava.cpp file. This is the new include, /usr/lib/jvm/java-1.7.0-openjdk-1.7.0.9.x86_64/include/jni.h. I then get an error with jni.h not being able to fine jni_md.h which is an include in jni.h #include "jni_md.h".
Clearly this is not the right approach, so perhaps I need a correct Ant reference, but I cannot seem to do it with a -lib switch. Besides, this just creates thousands of jni.h file errors during the Ant build attempt.
How can I fix this problem?
Notes: I've set$JAVA_HOME up like JAVA_HOME=/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.9.x86_64 and javac and java work fine.
New discovery... after helpful questions which guided me, I am much closer to successful compilation.
When I install LibusbJava and manually install all the library references in build.xml there is still an error compiling the LibusbJava based on a memset error. I see memset patches for libusb that appeared in 2007 and it's unclear how to use or if they relate. Investigating... Hints, comments and questions welcome. My most sincere thanks for the help thus far.
[exec] /.../libu/libusbjava/trunk/LibusbJava/objects/Usb_Device.cpp: In function ‘void Usb_Device_disconnect(JNIEnv*)’:
[exec] /.../libu/libusbjava/trunk/LibusbJava/objects/Usb_Device.cpp:88: error: ‘memset’ was not declared in this scope
[antcall] Exiting /.../libu/libusbjava/trunk/LibusbJava/build.xml.
BUILD FAILED
but I find no referece to an include string.h or cstring. The header of Usb_Device.cpp mentions it is a C++ Stub for the java class of a java class ch.ntb.inf.libusbJava.Usb_Device. which only has this include #include "Usb_Device.h" which also does not appear to have a string include. Perhaps just insertion of#include`?

Resources