Running Android app from Eclipse after setting up for obfuscation - java

So, this may be the stupidest question ever, but I can't figure it out.
I set up my project to use Proguard obfuscation when I export the APK. A couple weeks later, here I am making some changes to my app in preparation for an update, and I right click on my project and do Run As -> Android Application, just like I always used to while testing.
I was quite surprised to be greeted with a java.lang.NoClassDefFoundError, on the first line of my main method that references obfuscated code. The code compiles in Eclipse, but when run using Run As -> Android Application, it crashes immediately.
However, if I export an APK from Eclipse and manually install it on my phone, the app runs fine! It takes quite a while to export due to the obfuscation though, and while I'm testing it's a pain to wait for it every single time I want to test a change.
So I'm pretty sure this is related to obfuscation, Proguard, and the Eclipse build process. But I'm not sure exactly what's going wrong, or when.
I've tried cleaning the project, I've tried taking "proguard.config=proguard.cfg" out of my project.properties file. Somewhere along the line, something obfuscation-related happened to my project that makes my app un-runnable without exporting an APK. What causes this?
I was under the impression that doing Run As -> Android Application will NOT invoke Proguard. So what's going on?
(Note: The same thing happens using "Debug As" rather than "Run As")
EDIT 1
I've tried commenting out the proguard.config line in project.properties, cleaning the project, and rebuilding it. Same problem.
Additionally, I tried renaming/removing proguard.cfg, but the problem persisted.
Which got me thinking, maybe this isn't an obfuscation-related problem, but rather a project setup problem? But how could it work when exporting an APK yet crash when I Run As -> Android Application? Doesn't make sense.
EDIT 2
The solution is in a comment on the accepted answer. Thank you for putting me on the right path!

I suggest you disable proguard unless you're doing a release build. When you disable/enable proguard you will need to Project > Clean (and re-build if you don't have Project > Build Automatically checked; Project -> Build or CTRL-B).

Related

How to (manually) disable Eclipse jdt.ls compilation in Maven/Java projects

I currently have a Maven Java 11 project that builds fine. However, I use Eclipse's implementation of the language-server for editing the code within Emacs. This works fine, everything that I really need is available.
However, my question, is how can I disable the Eclipse LSP/compiler from attempting to auto-compile the project? It's not always an issue, but often the JDTLS seems to be recompile everything all the time to the point that when I run Maven, it has to recompile everything again. At best, this is a slowdown in the develop->test cycle. At worst, I have to clean build frequently.
Eclipse has an option in its GUI which "builds automatically". I am curious, is there a text file I can toggle this setting with?
According to the lsp-java documentation, the setting you are looking for is lsp-java-autobuild-enabled.
However, if there is a way to run the tests directly rather than via Maven, it would be faster since Maven does not support incremental compiling like JDT does (ideally, compiling should be done incrementally on save and not when running the application or a test).

Update Gradle in an existing java servlet jsp project

First a little background. I can go from netbeans 8.0 to 12 and open an existing older project that was built with netbeans native builder (pretty sure it's ant), do a clean and build, and the project runs perfect with zero problems. You can totally be unaware of build.
Now the problem, gradle. I did my first gradle project, all was good, ran fine. Then a few days later netbeans informed me there was an update to gradle, I updated, restarted the ide, and nothing. The project would not build anymore, etc.
How, and I plea for help here, how do you make it so you can update gradle, and just press on with a clean and build?
Meaning, I want to be unaware that gradle even exist, I should not have to spend time fixing a build tool, I should be able to update, and forget I’m even using it. Any help is appreciated.
Been using netbeans for years, and never encountered such a mess.
Also if it's not possible in netbeans, I'll use eclipse, but I'd like to not even think about the build tool just like in the past. Any hints, tips?
Or after an update to gradle, is there some little thing that needs to be done?
I have used native build for years, mostly netbeans and some in eclipse and never needed to read one word of the ant documentation, it just always works.

IntelliJ IDEA doesn't redeploy changes

I have a Spring Web application and when I debug with IDEA's debbuger in Tomcat and redeploy the project after some changes, the changes are not deployed and debugger "sees" the old code (stepping through wrong or empty lines). Only thing that helps is to run maven clean install and then start the Tomcat again.
I tried clearing IDEA caches but it didn't help.
Hotswap also doesn't work, although I have correct options selected in settings, but I can live with that.
Note that I use redeploy not hotswap, so the whole application is started again, it should reload all classes but it doesn't. Only after maven build it works.
Note 2: I think it work ok one month ago, but no changes I can think of could do this (project- or IDEA-wise)
EDIT: So hotswap is now working OK (magically, I didn't do anything). But when I make larger modifications (eg. method signature change, etc), they are not picked up during REDEPLOY to the server. So I neeed to run maven clean install and start the server again to see the changes and for hotswap to work properly after method body modifications on this new code. Any idea why?
You need to check your run configurations of tomcat, in "Before launch" there should be Make and Build artifact steps, also be sure that all you changed classes are really compiling during redeploy - this is the place I would start from.
Also I don't get why you use redeploy instead of hot-swap? Redeploy is usually same time-consuming as restart server, but hot-swap is nearly instant. Though it allows only to change method bodies and constants, usually it's much prefferable then redeploy in development. Personally I'm using JRebel which is free for non-commercial projects now and restart server very rare.
EDIT:
I don't know why your classes are old even after redeploy, but the reason is 99% that they do not compile after changes into exploded folder. Doing maven clean install after each code change is too much (IDE compilation should be enough).
What I can suggest you is not to redeploy but to restart server after big changes. So that IDE perform Make, Build artifact and Deploy artifact tasks.
In addition to david.lucky hints, make sure that on your Tomcat configuration in the deployment section you're using an exploded artifact
I had exactly the same problem! I've spent hours in solving this issue.
I don't know why, but the solution for me was that (I'm working on MacOS High Sierra):
First, I had some of my tutorial projects, I was working on, on my Desktop in a folder /Desktop/tutorial/... These project were working fine. I could redeploy and Tomcat was recognizing the changes in my java files.
Then I started some new, own projects, and I placed them in my home directory, something like /Users/myHomeDirectory/WebApps/.
I could build and run these objects, but when I made changes, I had the same exact problem, that Tomcat was not recognizing the result. Only thing that helped out, when I clicked Maven-Button "Reimport all Maven Projects".
I tried really lots of different things. Nothing worked.
Then I thought, maybe, theres something wrong with my project. So I took one of my projects from Desktop and copied them into my home directory. But suddenly, I had again the same problem.
So here's my solution: I created a new project on Desktop again. And I don't know why, but now it's working fine. I really have no clue why. And believe me, I did not change any settings. I did exactly the same!
And regarding the life reload without redeploying. This works really fine for me (without any plugins like JREbel):
Go Run –> Edit Configurations –> “Deployment” tab, clicks + icon –> select an “exploded artifact”
Select “Server” tab, update the following options :
On ‘Update’ action -> Update classes and resources
On frame deactivation -> Update classes and resources
Run web application in Debug mode. Try to modify some codes or resources (Java files, ...), the modified classes and resources will be reloaded automatically.
This has been happening me for some time now Ultimate Edition after switching from eclipse to Intellij a few months ago.
Standard tomcat config and debug settings mentioned above used.
Intellij will show green popup after nothing to reload or reloaded one class.
Yet the debuggers bytecode is not the same reloaded/updated code.
You can force a recompile which will work for small changes ctr shift F9.
Other than that a clean install seems to work for annotation, method definition changes etc. If you try a recompile the debugger will fail the server.
So the answer is ctrl shift F9 on the file you change

Sudden weird errors on a project

Today I came to work, happy. But when I opened my Eclipse, I saw that one of my projects has errors.It's weird because it shows that it has errors only in the window bar, and not in the Navigator. I don't have any Java errors, this is a valid project that was fine all the time:
Some of the errors on the error log of Eclipse:
JavaBuilder handling ImageBuilderInternalException while building: SP_Procedure
Cannot connect to VM
File <SomeFile> has been skipped, problem while reading ('Resource is out of sync with the file system')
Unhandled event loop exception
Internal error
When I run an application from this project, I get a warning message but when I proceed, it works fine, but still. It's very disturbing and I'm not sure if it's harmless.
I tried to:
Restart Eclipse
Restart my machine
Clean projects and recompiling them.
Refresh projects
Pray
Nothing helped. What could be the problem? (I'm using Indigo Service Release 2)
The following nuclear option has desperation written all over it. But I have been where the OP has been with the Juno version of Eclipse.
Run a "Synchronize with Repository" and save all of your local updates to a different directory.
Delete the project. (Check the box to delete the contents on disk. Scary step, but that's OK, because you saved it in a different directory in the previous step, right?)
Read in a fresh project from the repository. It builds happily at this point.
Integrate your local updates.
Keep on praying.
Looks that one unused JAR was deleted, but for some reason, I didn't get errors in any file, even in the files that imports this JAR! So what I did was restoring this JAR, delete unused imports and deleted the JAR again.
I've found this error after two days of navigating on this project on each file.. This is weird that Eclipse didn't recognize that1 this is an error, and throw many unrelated errors such as:
Cannot connect to VM
File has been skipped, problem while reading ('Resource is out of sync with the file system')
Unhandled event loop exception
Is this a bug in Eclipse? (All errors and warnings are enabled!)
1 As seen in the image in the question..
A class from the list of imports for the file seems to have moved out or the jar file containing the class is missing.
Expand the imports section and check if you find some classes that are missing but have been imported.
Though it is a pain, sometimes the easiest solution is to back up all your projects (either in a repository or somewhere else on your computer) then uninstall and reinstall eclipse. No it's not fun, but it should reset eclipse so everything works again. The downfall though is that you have to reconfigure eclipse to any special settings you had/reinatall any extra functionality currently installed (eg. android add-on) and reconnect to any repositories you have. While punting isn't fun, it can be effective... I hope you don't have to resort to this though.
I have went through that problem a lot of times, and tried everything you tried. Rebuild, recompile, refresh, remove and add JDK, remove and reinstall Eclipse... nothing worked
The only thing I concluded is that the workspace metadata was corrupted.
What I did (every time it happened) was
Create an empty workspace
Import -> existing projects into worskpace
Mark the "copy projects" (else it will only link them)
Wait for the copy, and start working with the new workspace
If you work with SCM systems (Git, SVN, etc), making a full checkout will do the trick too, but the worskpace import will let you retrieve those changes you didn't get to commit (if any).
It's a little painful if you have somethings already set (like JDK names, servers, etc), but then I realized it was faster than keep searching how to fix the workspace
Regards!
PS : I've been working with Kepler lately, and everything works fine till now
Click Window -> Show View -> Other -> General -> Problems
This view will show you what is wrong.
Did you, by any chance, update your virtual machine outside of Eclipse? I can't help but feel that we're both missing a finer detail here. I just keep seeing "cannot connect to VM" and thinking that it's a major clue.
Have you tried running anything from the terminal? Does it work there?
If so, do you know where your current edition of Java is located? Is Eclipse looking somewhere else?
Is this exclusive to one project? Do you use any additional libraries to the JDK?
Maybe try this for Resource is out of sync with the file system error:
Right click project in Eclipse Package Explorer
Close Project.
Right click project in Eclipse Package Explorer
Open Project.
Other things not mentioned:
project properties > java build path, see if any of those tabs got changed, local file got moved? read/write permissions on some file you are linking to?
project properties > java compiler, see if workplace settings have changed? maybe under errors/warnings, you can systematically set them to 'ignore' until the error goes away to determine what type of error it is?
maybe update some of the eclipse plugins?
I saw something like this happening for a number of reasons. Mainly because of validation in files other Java source code. See if you are validating XML for instance.
Right click your project and chose Properties (Alt+Enter) and Validation to see the related configuration.
As for the danger, I lived with those marks for ages and nothing wrong ever happened.

Can't Export Android Application in Eclipse

I'm experiencing some strange behavior in Eclipse. I'm trying to export my Android application, which is a game that is written using AndEngine, the open source game engine. Not sure if that is relevant.
Anyway, there are no errors in my project or the library dependencies of Android. I have been running the application on my phone with the debug build for ages. Now I want to export a signed application, and it won't work! (It did used to).
I right click my project, click Android Tools > Export Signed Application and right when I do that, two errors show up that say,
No .class files were found in project "AndEngine" so none of the classfile basechecks could be run . Does the project need to be built first?
No .class files were found in project "AndEnginePhysicsBox2DExtension" so none of the classfile basechecks could be run . Does the project need to be built first?
How the heck do I fix this? I have done a Project > Clean, open and closed Eclipse, open and closed the individual projects. And again - this error is NOT there until I go to export the app! What the heck!
Ok I think I figured this out. Not sure of the "real" issue, but my workaround for the time being is to right click my project in the file tree on the left, then click Properties. I selected the "Android Lint Preferences" in the dialog that comes up, and just hit "Ignore All". Now I can build without the error.
While this is a work around, I'm not thrilled about leaving that disabled completely. I'd like to know which Lint preference i can specifically disable. (I, quite frankly, don't even know what lint is)
I solve this problem turning off Build Automatically in Eclipse before export.
Are those projects set as libraries?
Open Project -> Properties.
Click Android on the left.
Scroll down and make sure under Libraries that "Is Library" is checked.
probably just add:
<issue id="LintError" severity="ignore" />
to your lint.xml config file.
In eclipse probably just set this one (LintError) error to ignore.

Categories

Resources