Skip to content
This repository has been archived by the owner on Jan 9, 2020. It is now read-only.

Error when running a signed APK #92

Closed
pinicius opened this issue Feb 22, 2018 · 17 comments
Closed

Error when running a signed APK #92

pinicius opened this issue Feb 22, 2018 · 17 comments

Comments

@pinicius
Copy link

Hi,
I do not understand what is happening.

  • When I install the app from Android Studio with the debugkeystore by default, there is no problem.
  • When I sign the app with the Android Studio tool and my keystore, then I pass it to the phone, install the app, execute and ERROR: This object does not contain any use case to execute. Did you forget to add the @usecase annotation?

Why these two different behaviors with the same code?

Has something similar happened to you?

Thanks in advance

@pedrovgs
Copy link
Contributor

Hi @pinicius! This is the first time we face this issue and I'm pretty sure it is related to the obfuscation configuration. When you say "When I install the app from..." are you talking about this repository code or your own app?

@pedrovgs pedrovgs changed the title O_o Error Error when running a signed APK after executing a use case Feb 22, 2018
@pinicius
Copy link
Author

pinicius commented Feb 22, 2018

Hi @pedrovgs!
I want mean, from my own app.
I think the problem is related to that too, but I don't want to make any obfuscation at this point. Any clue?

    buildTypes {
        debug {
            debuggable true
            minifyEnabled false
        }
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

@pedrovgs
Copy link
Contributor

pedrovgs commented Feb 22, 2018

@pinicius could you check in your project if your release build obfuscates the app. If I remember well, Rosie does not support obfuscation.

@pinicius
Copy link
Author

In both is disabled

@pedrovgs
Copy link
Contributor

If this is your build tyes configuration:

    buildTypes {
        debug {
            debuggable true
            minifyEnabled false
        }
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

You are adding the default proguard-android.txt and also the proguard-rules configuration file to your proguard execution. So the obfuscation could be enabled. Could you double check it?

@pedrovgs
Copy link
Contributor

If you could also paste the stack trace you've found that'd be great 😃

@pinicius
Copy link
Author

:app:preBuild UP-TO-DATE
:app:preReleaseBuild UP-TO-DATE
:app:compileReleaseAidl UP-TO-DATE
:app:compileReleaseRenderscript UP-TO-DATE
:app:checkReleaseManifest UP-TO-DATE
:app:generateReleaseBuildConfig UP-TO-DATE
:app:prepareLintJar UP-TO-DATE
:app:generateReleaseResValues UP-TO-DATE
:app:generateReleaseResources UP-TO-DATE
:app:mergeReleaseResources UP-TO-DATE
:app:createReleaseCompatibleScreenManifests UP-TO-DATE
:app:processReleaseManifest UP-TO-DATE
:app:splitsDiscoveryTaskRelease UP-TO-DATE
:app:processReleaseResources UP-TO-DATE
:app:generateReleaseSources UP-TO-DATE
:app:javaPreCompileRelease UP-TO-DATE
:app:compileReleaseJavaWithJavac UP-TO-DATE
:app:compileReleaseNdk NO-SOURCE
:app:compileReleaseSources UP-TO-DATE
:app:lintVitalRelease
:app:mergeReleaseShaders UP-TO-DATE
:app:compileReleaseShaders UP-TO-DATE
:app:generateReleaseAssets UP-TO-DATE
:app:mergeReleaseAssets UP-TO-DATE
:app:transformClassesWithPreDexForRelease UP-TO-DATE
:app:transformDexWithDexForRelease UP-TO-DATE
:app:mergeReleaseJniLibFolders UP-TO-DATE
:app:transformNativeLibsWithMergeJniLibsForRelease UP-TO-DATE
:app:transformNativeLibsWithStripDebugSymbolForRelease UP-TO-DATE
:app:processReleaseJavaRes NO-SOURCE
:app:transformResourcesWithMergeJavaResForRelease UP-TO-DATE
:app:validateSigningRelease
:app:packageRelease UP-TO-DATE
:app:assembleRelease

BUILD SUCCESSFUL in 2s
26 actionable tasks: 2 executed, 24 up-to-date

But I don't know how to avoid it :(

@pedrovgs
Copy link
Contributor

Here you can find information about how to avoid obfuscation during your build. Could you update your app and let me know if this is the issue you are facing?

@pinicius
Copy link
Author

Unfortunately it does not work. I've tried with the signed debug version too and the error is the same, does it make sense?

@pedrovgs
Copy link
Contributor

But you said:

When I install the app from Android Studio with the debugkeystore by default, there is no problem.

I think the easiest way to figure out what's going on is to create an android project from scratch, upload it to a public repository and try to reproduce the bug. Could you do this so we can find the issue and fix it?

@pinicius
Copy link
Author

I meant to sign the release of debug with my private keystore (releasekeystore)

After feeding, I will try :D

Thanks so much for your time

@pinicius
Copy link
Author

pinicius commented Feb 22, 2018

Hi again @pedrovgs,
I have solved the problem, the use case method was not public :$
But now, the app gives me an error when I run the signed APK

java.lang.Error
                                                                                    at com.karumi.rosie.domain.usecase.error.ErrorFactory.createInternalException(ErrorFactory.java:42)
                                                                                    at com.karumi.rosie.domain.usecase.error.ErrorHandler.createError(ErrorHandler.java:91)
                                                                                    at com.karumi.rosie.domain.usecase.error.ErrorHandler.notifyException(ErrorHandler.java:64)
                                                                                    at com.karumi.rosie.domain.usecase.UseCaseWrapper.notifyException(UseCaseWrapper.java:47)
                                                                                    at com.karumi.rosie.domain.usecase.UseCaseWrapper.execute(UseCaseWrapper.java:41)
                                                                                    at com.karumi.rosie.domain.usecase.jobqueue.UseCaseWrapperJob.onRun(UseCaseWrapperJob.java:41)
                                                                                    at com.path.android.jobqueue.Job.safeRun(Job.java:189)
                                                                                    at com.path.android.jobqueue.JobHolder.safeRun(JobHolder.java:91)
                                                                                    at com.path.android.jobqueue.executor.JobConsumerExecutor$JobConsumer.run(JobConsumerExecutor.java:306)
                                                                                    at java.lang.Thread.run(Thread.java:764)

But the two uses cases have been executed correctly because I see in the log that the data has been load from remote and saved into database :/

The error referenced in ErrorFactory.java in line 42 it does not seem to be a TargetException or InvocationTargetException, what kind of error is happening? Why not happens executing with debugkeystore?

This error not appears when I run from my repository

public class GetExperiments extends RosieUseCase {

    private static final String TAG = GetExperiments.class.getSimpleName();

    private final LocalDataSource localDataSource;

    @Inject GetExperiments(LocalDataSource localDataSource) {
        this.localDataSource = localDataSource;
    }

    @UseCase public void getExperiments() throws Exception {
        Collection<Experiment> experiments = localDataSource.getAllExperiments();
        Log.d(TAG, "getExperiments: EXPERIMENTS ACTIVE SIZE: " + experiments.size());
        notifySuccess(experiments);
    }
}

In both (debug and release) experiments size returns a value. Neither of the two use cases seems to be failing.

Any idea?

@pedrovgs
Copy link
Contributor

Happy to see you've found the original issue. In order to fix this you should debug the code execution and review what's the exception thrown. The code you can see in the stack trace is only executed if someone throws an exception, so at some point your code has to be throwing an exception you are not handling. Do you still face this issue just with the signed/release version of your app? Did you disable the obfuscation as I suggested in a previous comment? Disabling obfuscation will help us to identify where the bug is.

@pinicius
Copy link
Author

Hi @pedrovgs !
Unfortunately I'm still with the problem.
I have verified that if the minified property is false, it does not perform code reduction.
The use cases, including the components they are using, do not throw any type of exception. In fact, the information is in the database. I have a doubt, if minified is deactivated, can obfuscation occurs? Because as I have looked in the documentation there should be a folder in the path / build / outputs / mapping / release / and it does not create them.

But the problem continues, if I generate the apk signed with my keystore, any type of build (debug or release), the application fails. If I sign with debugkeystore, no problem. And in both cases the information is in database without any error.

Right now I do not know where to look :(

@pedrovgs
Copy link
Contributor

@pinicius minification is not equivalent to obfuscation, so if you don't minify the app you can still be obfuscating it as I commented here. If you are not able to disable the obfuscation and we can't find a way to reproduce this error..there is only one way to fix this. Create a repository on GitHub where you reproduce the error and share it with us so we can debug it manually and see what's going on.

@pedrovgs pedrovgs changed the title Error when running a signed APK after executing a use case Error when running a signed APK Feb 23, 2018
@pinicius
Copy link
Author

@pedrovgs One last question

I have added the code they discuss in the possible solution (link that you made me reference)

Even without using Proguard, the behavior is the same.

release {
            debuggable true
            minifyEnabled false
            useProguard false
            shrinkResources false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }

I do not understand what is going on, why does not it always fail?
I will continue trying to solve it. Thank you very much for your time and if you have any ideas, it will be welcome ;))

@pedrovgs
Copy link
Contributor

You are welcome @pinicius I'm closing this issue for now until we have a clear scenario to reproduce the error in our hands. Feel free to create the repository I mentioned so I can personally debug what's going on.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants