Class not found exception when using Multidex - android

So my problem is I'm getting Class not found error while running the app on my device.
"io.tutorial.app.App" class not found at the path io.tutorial.app
Actually the class App.java is present at that path and also my class is extending MultiDexApplication .
What I found so far is two dex files have generated in the built apk namely classes.dex and classes2.dex. The weird thing is the package "io.tutorial.app" is present at both dex files (I think this is the issue). There's no classes present at the "io.tutorial.app" package in the classes2.dex file but all my classes are present in classes.dex file under the same package "io.tutorial.app". Please help me to find a solution to this.
Manifest:
<application
android:theme="#style/AppTheme"
android:label="#string/app_name"
android:icon="#mipmap/ic_app"
android:name="io.tutorial.app.App"
android:allowBackup="true"
android:supportsRtl="true"
tools:ignore="GoogleAppIndexingWarning">
<activity
android:theme="#style/AppTheme.NoActionBarFullScreen"
android:name=".ui.activity.SplashActivity"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
Gradle:app
https://pastebin.com/JpkRZY1G
App Class:
public class App extends MultiDexApplication {
#Inject
Cache cache;
public void onCreate() {
AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
super.onCreate();
initRemoteConfig();
Injector.getInstance().init(this);
Injector.getInstance().appComponent().inject(this);
initFabric();
initRealm();
initPicasso();
initRemoteConfig();
initAds();
initOneSignal();
}

I'd have that #Inject annotation under suspicion - or the use of Injector.
try to use MultiDex.install() instead:
public class App extends Application {
...
#Override
protected void attachBaseContext(Context context) {
super.attachBaseContext(context);
MultiDex.install(this);
}
}

Related

ClassNotFoundException: after obfuscation

I am creating a library. My library has method for open another activity
val ACTION: String
get() = "org.comp.sign.Auth"
internal fun createIntent(input: Pair<AuthorizationParams, Config>): Intent {
return Intent(ACTION).apply {
val loggingData = input.first.parseToPair()
putExtra(PARAMS_TYPE, loggingData.first)
putExtra(PARAMS_FIELD, loggingData.second)
putExtra(CONFIG_DATA, input.second.toData())
}
}
I used to intent-filter cause I would like to do obfuscation in my code, if was opening it without
intent-filter my Activity class would not be obfuscation
library's manifest
<activity
android:name=".config.internal.ui.view.CompActivity"
android:exported="false"
android:screenOrientation="portrait"
android:theme="#style/Theme.Auth">
<intent-filter>
<action android:name="org.comp.sign.Auth" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
when i implementation my lib in another project i throw a exception
java.lang.ClassNotFoundException: org.comp.sign.auth.a.a.d.a.a
Project was finding Activity class, but it has different name
If I used to save class with the proguard rule -keep class !org.comp.sign.auth.config.internal.ui.view.CompActivity
then in my library will be many another files that disappeared when obfuscation
If there is a way around this?
Sorry for my English

Custom Application class onCreate() never called

I'm trying to initialize Parse on a custom Application class:
import android.app.Application;
import android.util.Log;
import com.parse.Parse;
import com.parse.ParseException;
import com.parse.ParseInstallation;
import com.parse.SaveCallback;
public class SomeApplication extends Application {
#Override
public void onCreate() {
super.onCreate();
initializeParse();
}
private void initializeParse() {
Parse.setLogLevel(Parse.LOG_LEVEL_VERBOSE);
Parse.initialize(new Parse.Configuration.Builder(this)
.applicationId("##########")
.clientKey("############")
.server("https://#####.com/parse/")
.build()
);
ParseInstallation installation = ParseInstallation.getCurrentInstallation();
installation.saveInBackground(new SaveCallback() {
#Override
public void done(ParseException e) {
// Do something here
}
});
}
}
And I already declare this Application in AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.test.someproject">
<uses-permission android:name="android.permission.INTERNET" />
<application
android:name=".SomeApplication"
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".AnotherActivity"/>
</application>
</manifest>
But my custom Application is never called. I tried to put logs and break points on onCreate method, clean project, rebuild project, close and re-open Android Studio, uninstall and reinstall the app and nothing ... so, I need help.
Thanks!
Disable Instant Run, Clean build, Rebuild the project and then run again.
I had the same issue. Disabling instant run worked for me. It is weird Application class not getting called. But it happened.
In my case I forgot about declaration in the manifest:
<application
android:name=".App"
...>
This worked for me - try using this property in your Manifest file:
<application
android:name=".SomeApplication"
android:usesCleartextTraffic="true"

WakefulBroadcastReceiver get java.lang.ClassNotFoundException

In my Android project, I have a Service class:
public class MyService extends Service{
...
//Defined a WakefulBroadcastReceiver as a inner static class
public static class DeviceRebootReceiver extends WakefulBroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
//Do something when user reboot the device
}
}
}
As you see above, I have defined a WakefulBroadcastReceiver as a inner static class in MyService class. This receiver receives the broadcast when user reboot his/her device.
My AndroidManifest.xml looks like this:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.my.project"
android:versionCode="1"
android:versionName="2.1" >
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<application
...>
<activity ...> ... </activity>
<service android:name="com.my.project.MyService"
android:exported="false"/>
<receiver
android:name="com.my.project.MyService$DeviceRebootReceiver"
>
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
</application>
</manifest>
But when I run my app & after rebooted the device, my logcat shows me error:
Unable to instantiate receiver com.my.project.MyService$DeviceRebootReceiver:
java.lang.ClassNotFoundException: com.my.project.MyService$DeviceRebootReceiver in loader dalvik.system.PathClassLoader[/data/app/com.my.project-1.apk]
Why my receiver class is not able to be loaded by system?
=====Update======
I also tried to make my DeviceRebootReceiver as a separate class (DeviceRebootReceiver.java), and made the AndroidManifest.xml changed to :
<application...>
<receiver
android:name="com.my.project.DeviceRebootReceiver"
>
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
</application>
But I still get the similar error in logcat:
java.lang.RuntimeException: Unable to instantiate receiver com.my.project.DeviceRebootReceiver: java.lang.ClassNotFoundException
I had the same problem and solved it.
It's about the android-support-v4.jar library, you should only have the official and updated library (copied from ANDROID_SDK/extras/android/support/) under the libs folder in your project and Android Private Libraries checked in the Java Build Path of your project. For example, I also had a ClassNotFoundException because of my project was using the android-support-v4.jar of another library (ActionBarSherlock) even with the official android-support-v4.jar included in my java build path, so I unchecked the Android Private Libraries of the ActionBarSherlock project to avoid this redundancy.

Subclass activity from a jar getting ClassNotFoundException

I have two Android projects. One is a library and compiles a jar the other an executable which includes this jar on the build path.
I'm subclassing an activity in the jar in my project but when I start it I'm getting a ClassNotFoundException.
Here's the manifest with the activity in question being MainActivity:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.my.package.MyProject"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="8" />
<application android:label="#string/app_name"
android:name=".MyApplication"
android:icon="#drawable/ic_launcher"
android:theme="#style/AppTheme">
<activity android:label="#string/app_name"
android:configChanges="orientation|keyboardHidden"
android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
And here is my MainActivity, where the QCARSamples package is found in my jar:
package com.my.package.MyProject;
import java.io.File;
import com.qualcomm.QCARSamples.ImageTargets.GraphicsEngineHook;
import com.qualcomm.QCARSamples.ImageTargets.VuforiaTrackingActivity;
import com.my.package.MyProject.R;
public class MainActivity extends VuforiaTrackingActivity{
private File blenderFile;
#Override
protected synchronized void updateApplicationStatus(final int appStatus){
return;
}
#Override
protected GraphicsEngineHook getGraphicsEngineHook() {
return new MyGraphicsEngineHook();
}
#Override
protected int getSplashScreenImageResource() {
return R.drawable.splash_screen_image_targets;
}
}
I also tried including the activity I'm subclassing in my manifest like so, but I was still getting the same error:
<activity>
<android:name="com.qualcomm.QCARSamples.ImageTargets.VuforiaTrackingActivity>
</activity>
Any ideas?
The problem is usually on the BuildPath.
Assuming you're using eclipse and ADT:
Right click on your project, select Build Path -> Configure Build Path -> Order and Export and make sure that your library is selected.
Remember to clean the project before trying again.
it could also be the class path as the guy suggested on the commented, on the manifest, instead of editing direct the XML, go to the Application tab, select the activity, click Browser, uncheck 'Display classes from sources of Project ...', and select the Activity from your library.

Simple android application with roboguice throwing exceptions

I have a very simple application that works but when i add roboguice it throws
java.lang.RuntimeException: Unable to instantiate application
com.MyFirstApp.MyFirstApplication: java.lang.ClassNotFoundException:
com.MyFirstApp.MyFirstApplication
The application class:
public class MyFirstApplication extends RoboApplication {
#Override
protected void addApplicationModules(List<Module> modules) {
//modules.add(new DefaultModule());
}
}
The MainActivity:
public class MainActivity extends RoboActivity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}
the manifest:
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.MyFirstApp"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="14" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:name="MyFirstApplication">
<activity
android:name="com.MyFirstApp.Activities.MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action
android:name="android.intent.action.MAIN" />
<category
android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
I have put guice-2.0-no_aop.jar and roboguice-1.1.3.jar in the assets folder and added them to the buildpath.
when i remove the robo part it works fine. can anyone tell me what i did wrong.
Well i found out what the problem was. i was using SDK v17+ and in that version external library's need te be placed in a "libs" folder and only in the libs folder. so all the tutorial's i found where they just put it in the assets folder where wrong.
Link to where i got the answer i was looking for: http://groups.google.com/group/roboguice/browse_thread/thread/474116b052050ae2
First of all, extending from RoboApplication is a RoboGuice 1.x thing, you should really be using RoboGuice 2.0 (where you no longer need to do that). Now, for your exception, is your Application class really at com.MyFirstApp.MyApplication? If not, you would need to update the name attribute to match.

Categories

Resources