We've recently migrated from VS2017 to VS2019, building Xamarin Forms applications. We've had no problems with obfuscation for years and years, but now we've got a showstopper. To summarise: the project DLL inside the final APK file is the un-obfuscated version, not the obfuscated version.
If we build the Android app normally (in a Release configuration) it works fine: decompiling the file shows the obfuscated code as expected - completely unintelligible. It also successfully copies this from its working 'dfout' folder (under 'obj') to the 'bin' folder, so the build process propogates the obfuscated file as it should; everything is cool.
But...when you run 'Archive' to create an APK file...things work differently. After many hours of close examination we worked out exactly is happening, but we don't know why, and how to fix it: the project DLL (that should go inside the APK) is getting taken from the un-obfuscated code. The obfuscation then runs after the packaging has completed, leaving the correct DLLs in the 'obj' and 'bin' folders, but the one inside the packaged APK is the un-obfuscated version.
What on earth is going on here?
Found the solution to this in the comment thread of another StackOverflow question.
Basically it's an issue with Dotfuscator working with VS2019, which requires some new Dotfuscator targeting files to work. Initially these too didn't work, but after deleting all bin and obj folders and restarting VS in Admin mode did the trick.
Dotfuscator obfuscates stand alone assembly but not the APK archive
Related
Im not really sure how to being this... this started a couple months ago every so often i would receive apk install failed errors and when i unzipped my built apk and looked at the android manifest mine was replaced with a android manifest from a sample serial port library i was testing with a while back. This problem has become constant to the point where every 3 builds or so i have to use the visual studio installer to repair visual studio. Cleaning the solution doesn't fix it nor does deleting my local visual studio files or bin/obj folders. I have cloned my solution over to my personal desktop and it built fine and has never exhibited these problems so i believe its environment specific. if anyone has run into a similar problem or has any suggestions i would greatly appreciate it.
With Xamarin.Android some of the AndroidManifest.xml file is generated at build time.
All types which have [Application], [Activity] or [Service] attributes and their extra stuff like [IntentFilter], [MetaData] will be added to the manifest at build time.
You can verify this by comparing Properties/AndroidManifest.xml to the one generated which usually can be found in the obj/Debug/Android folder. You should see that your Activities are added there.
If you use the Xamarin.Android.ManifestMerger package, additional content from Android Libraries might be added to the manifest as well
I found the problem! the newest non preview xamarin android will do this if you have a bound jar . here is a link to the github issue this should be fixed in future versions for now im updating to the preview visual studio.
https://github.com/xamarin/xamarin-android/issues/4804
I have an Android Studio projet that depends on an external .so file compiled with another IDE. Whenever my .so is linked, I copy and paste it into the src/main/jniLibs/armeabi-v7a folder of my Android project, erasing the existing one, if any.
However, most of the time, it seems like Android Studio is not taking that change into account and keeps reusing the old version of the .so file. Sometimes it works, sometimes it doesn't, and I have not figured out what exactly is causing it to or not to work.
How can I do for the .so file to be updated ? I saw an SO answer providing a piece of gradle script to manually copy the .so file, but it doesn't fit my particular case since I have multiple .so files, one debug and one release for each CPU.
Android R IDs are generated by the IDE (Android Studio or Eclipse ADT).
Are they identical between builds?
If yes, will they be the same if generated on different machines?
Firstly, Android IDs are not generated by the IDE but by aapt, a command line tool which is run during a build. Yes, the IDE ultimately triggers it, but it isn't strictly part of Android Studio, it's part of the build tools package.
The numbers are essentially assigned alphabetically, so the resource IDs will be identical for the same project - but not if you modify the resource file tree. I am only prepared to guarantee that on the same file system, operating system and version of build tools. If you change any of those, all bets are off.
Ultimately, relying on this would be a really bad idea, because someone will break it by modifying the project one day, probably sooner rather than later.
I looked into this fairly extensively some years ago when I wrote an APK decompiler for the purposes of patching in resources.
When I install my app on a genymotion simulater device,it can not be installed well,on console I got "INSTALL_FAILED_CPU_ABI_INCOMPATIBLE"
I trid another app,it installed fine.I do not know why.
The application (certainly a game) must be ARM only.
Genymotion is a x86 platform, so compile the application to target x86.
You may be able to install ARM support manually :
http://forum.xda-developers.com/showthread.php?t=2528952
If you are using IntelliJ it may be related to the project's default configuration. IntelliJ will assume, unless otherwise specified, that Native libraries will be stored in the Libs folder. This is usually where developer store their JAR libraries. IntelliJ build process will package up the JAR file into the Native file folder in the APK.
If you experiencing this problem, you can find a good How-to:
INSTALL_FAILED_CPU_ABI_INCOMPATIBLE Intellj
This helped to resolve the issue I had.
You might want to check out my answer here:
INSTALL_FAILED_CPU_ABI_INCOMPATIBLE on device using intellij
I know it's written for IntelliJ, but you could be running into a similar issue with Eclipse where it thinks that some normal Java files or jar libraries are native code and including it in the compiled APK. A quick way to find out is to open up the final APK (it's just a jar file, so most utilities should be able to decompress it) and make sure that the only things you see are META-INF, res, AndroidManifest.xml, classes.dex, and resources.arsc. It's possible that there are other valid files in a normal Java Android application, but in general if you see anything else in there, particularly a libs folder, it's probably the result of the compilation process thinking that those other things are native libraries (compiled C/C++ code using the JNI).
If this is the case, you'll need to configure Eclipse to not interpret the Java libraries you're using as native code. Now, I don't personally use Eclipse so I don't know where the proper settings would be, but based off of this answer, it looks like Eclipse automatically assumes that the libs folder in the root of your project contains native libraries. The easiest solution may be to move any Java libraries you are using into a different folder (such as libraries).
http://blog.iteedee.com/2014/02/android-install_failed_cpu_abi_incompatible-intellj/
The INSTALL_FAILED_CPU_ABI_INCOMPATIBLE error is generated when you attempt to install an android application on a device with an unsupported CPU architecture. This error is usually related to the native libraries that are not packaged up for the device’s CPU architecture (ie: x86, ARMv6, ARMv7, etc).
Now, if you have an application that doesn’t use any native libraries or *.so file you might be scratching your head on this one. If you use IntelliJ IDEA IDE for your android development it might be packaging all of your related .JAR file in to the Native Library file location in your APK.
The cause of the same problem was different in my case.
I had added some dependency jars in /libs directory of my Android app project. One of these jars had exported library in jar format; i.e. a jar within a jar file. I've noticed that the apk created using jars with such structure are incompatible with x86 based devices (don't know why).
I've got an Android project built under Eclipse-Indigo that works just fine. I recently copied many of the files and rebuilt under Eclipse-Juno. The app runs if you install it and/or run it from Eclipse, but if you try to generate an APK, you get:
Conversion to Dalvik format failed: Unable to execute dex: multiple dex file define Landroid/bluetooth/IBluetooth;
Comparing the directories shows that src/android.bluetooth/IBluetooth.aidl and IBluetoothCallback.aidl are identical, but gen/android.bluetooth exists in the working version but not the broken one. Replacing these files manually makes Eclipse whine, of course, so the question is:
how do I control how Eclipse generates those particular files from the AIDL inputs?
Alternatively, if somebody has an intelligent suggestion as to how to get rid of the stupid error, I'll take that instead :-)
The answer is to NOT install the Android Development Kit, which seems to have borked libraries. Instead, install Eclipse for Java Developers, and install the Android SDK separately. This allowed the correct libraries to appear, and didn't give the stupid errors about duplicate dex files.