Android project, folder name

When I created this test Android project, Fire suggested org.somesuch.projectname as the folder/project name. I changed it to something else (ex.: “MyProject (Android)”) and made sure to update the project settings to use the proper default package name. The app builds but when I try to launch it I get a ClassNotFoundException:

2018-11-15 13:53:23.428 5846-5846/? E/AndroidRuntime: FATAL EXCEPTION: main
    Process: org.somesuch.projectname, PID: 5846
    java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{org.somesuch.projectname/org.somesuch.projectname.ProjectsActivity}: java.lang.ClassNotFoundException: Didn't find class "org.somesuch.projectname.ProjectsActivity" on path: DexPathList[[zip file "/system/framework/org.apache.http.legacy.boot.jar", zip file "/data/app/org.somesuch.projectname-j7kUBIBEaKqTwZY5xOcybA==/base.apk"],nativeLibraryDirectories=[/data/app/org.somesuch.projectname-j7kUBIBEaKqTwZY5xOcybA==/lib/x86_64, /system/lib64]]
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2843)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048)
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:193)
        at android.app.ActivityThread.main(ActivityThread.java:6669)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
     Caused by: java.lang.ClassNotFoundException: Didn't find class "org.somesuch.projectname.ProjectsActivity" on path: DexPathList[[zip file "/system/framework/org.apache.http.legacy.boot.jar", zip file "/data/app/org.somesuch.projectname-j7kUBIBEaKqTwZY5xOcybA==/base.apk"],nativeLibraryDirectories=[/data/app/org.somesuch.projectname-j7kUBIBEaKqTwZY5xOcybA==/lib/x86_64, /system/lib64]]
        at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:134)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
        at android.app.AppComponentFactory.instantiateActivity(AppComponentFactory.java:69)
        at android.app.Instrumentation.newActivity(Instrumentation.java:1215)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2831)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048) 
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78) 
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108) 
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808) 
        at android.os.Handler.dispatchMessage(Handler.java:106) 
        at android.os.Looper.loop(Looper.java:193) 
        at android.app.ActivityThread.main(ActivityThread.java:6669) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858) 
    	Suppressed: java.lang.NoClassDefFoundError: Failed resolution of: Landroid/support/v7/app/AppCompatActivity;
        at java.lang.VMClassLoader.findLoadedClass(Native Method)
        at java.lang.ClassLoader.findLoadedClass(ClassLoader.java:738)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:363)
        		... 15 more
     Caused by: java.lang.ClassNotFoundException: android.support.v7.app.AppCompatActivity
        at java.lang.VMClassLoader.findLoadedClass(Native Method)
        at java.lang.ClassLoader.findLoadedClass(ClassLoader.java:738)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:363)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
        		... 18 more
     Caused by: java.lang.NoClassDefFoundError: Failed resolution of: Landroid/support/v4/app/FragmentActivity;
        		... 18 more
     Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.v4.app.FragmentActivity" on path: DexPathList[[zip file "/system/framework/org.apache.http.legacy.boot.jar", zip file "/data/app/org.somesuch.projectname-j7kUBIBEaKqTwZY5xOcybA==/base.apk"],nativeLibraryDirectories=[/data/app/org.somesuch.projectname-j7kUBIBEaKqTwZY5xOcybA==/lib/x86_64, /system/lib64]]
        at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:134)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
        		... 18 more

Your application app manifest is likely still referencing the activity in the original package name.

Had you merely changed the directory name you might have been Ok (as long as any file path references were correctly updated); this problem has likely arisen because you also changed the default package name (the two things don’t have to be the same) and there are things in the original project which will still be based on the original package name, irrespective of the names of folders in the file system.

Qualification of activity class names in the manifest is one such thing.

My manifest specifies:

package="org.somesuch.projectname"

and the activity is declared as follows:

<activity android:label="@string/app_name" android:name=".ProjectsActivity">
...

This is confusing.

I deleted older builds of the test app from the emulator and now the app does not launch. I get a dialog box from Fire saying:

The process failed to start with the following error: Starting: Intent { cmp=org.somesuch.projectname/.ProjectsActivity }
Error type 3
Error: Activity class {org.somesuch.projectname/org.somesuch.projectname.ProjectsActivity} does not exist.

Ok, there’s a few things to this.

For now, oi assume the issue is specific to debugging only, and the app launches fine standalone. What happens is that — different form debugging on other platforms — the debugger on Android doesn’t just launch “the app”, but a specific activity. in this case. Fire is passing org.somesuch.projectname.ProjectsActivity as the activity it want to launch — and that class does not exist.

The error could be omg two sides: (a) this is the right activity you want to launch, but your class is named badly or (b) your class is named as it should be but this is not its name.

Now, the name of your activity class is (summing you’re using Swift, as I recall?) composed of the RootNamespace setting of your project, and the actual name you give to it in code. (in other languages, the namespace too is in code, at the top of the file).

So, I recommend checking of this are set as you expect, to make sure your activity class gets the name you want it to have. Chances are when you renamed your package, you didn’t change the root namespace, so your classes are still named with the old namespace.

The name of the activity to launch can be set in Fire’s project settings, under the “Start-Up Activity” / AndroidDebugActivity setting. When not set explicitly, it is determined by looking at all the activities in your manifest, and picking the one with android.intent.action.MAIN set. the name configured fo that activity will be used.

Can you check if either that project setting is set or, if not, an unexpected name is specified in the manifest file for the main activity?

The names (root namespace + class name + startup activity) should be correct in the sample project I sent you via PM. They are not the same as the ones in this post but I did check them.

Well, one of thew two sce3arios I described a above ha store mismatch. so which name is wrong?

That’s, for now, if we assume the android os isn’t lying to us, when it says the activity doesn’t exist.,…

Project settings:

Android SDK: android-28
Binary Name: ProjectName
Default Namespace: org.somesuch.projectname
Start-Up Activity: .ProjectsActivity

ProjectsActivity.swift:

public class ProjectsActivity: AppCompatActivity {
    // ...
}

AndroidManifest.android-xml:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="org.somesuch.projectname"
    android:versionCode="1"
    android:versionName="1.0">
    <application
        android:label="@string/app_name"
        android:icon="@drawable/icon">
        <activity android:label="@string/app_name" android:name=".ProjectsActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>
    </application>
    <uses-sdk android:minSdkVersion="15"/>
</manifest>

try setting the startup activity to the full name… if that does the trick, i’ll see if i can fix what fire doesn’t handle this…

It seems I get a timeout starting the app if I use .ProjectsActivity (and then get the Fire popup mentioned a few replies up). If I use the full org.somesuch.projectname.ProjectsActivity name (and ensure the project settings match that activity name) the app seems to launch but then throws the ClassNotFoundException described in the original post.

Ok, good. that means we solved the second problem then. Form today’s upcoming build. the debugger will handle getting a name without the namespace, and the IDE is fixed to provide the full names in the picker.

So as for the original issue: I assume “org.somesuch.projectname.ProjectsActivity” is the NEW name that the class SHOULD have but its not there? if you unzip the .jar or the .dex file, so you see the class in there?

Also, is the exception actually terminal? it seems that Android checks a multitude of paths for the class (not all of which will have it, of course), and each attempt throws an exception. thats “normal” (for what Java considers “normal”), and the app might still run in the end?

I unzipped the apk and then called dexdump on the classes.dex file. Here is the section on my activity class:

Class #1380            -
  Class descriptor  : 'Lorg/somesuch/projectname/ProjectsActivity;'
  Access flags      : 0x0001 (PUBLIC)
  Superclass        : 'Landroid/support/v7/app/AppCompatActivity;'
  Interfaces        -
  Static fields     -
  Instance fields   -
  Direct methods    -
    #0              : (in Lorg/somesuch/projectname/ProjectsActivity;)
      name          : '$onCreate$b__0'
      type          : '(Landroid/view/View;)V'
      access        : 0x0008 (STATIC)
      code          -
      registers     : 1
      ins           : 1
      outs          : 0
      insns size    : 1 16-bit code units
      catches       : (none)
      positions     :
        0x0000 line=19
      locals        :
        0x0000 - 0x0001 reg=0 view Landroid/view/View;
    #1              : (in Lorg/somesuch/projectname/ProjectsActivity;)
      name          : '<init>'
      type          : '()V'
      access        : 0x10001 (PUBLIC CONSTRUCTOR)
      code          -
      registers     : 1
      ins           : 1
      outs          : 1
      insns size    : 4 16-bit code units
      catches       : (none)
      positions     :
      locals        :
        0x0000 - 0x0004 reg=0 this Lorg/somesuch/projectname/ProjectsActivity;
  Virtual methods   -
    #0              : (in Lorg/somesuch/projectname/ProjectsActivity;)
      name          : 'onCreate'
      type          : '(Landroid/os/Bundle;)V'
      access        : 0x0001 (PUBLIC)
      code          -
      registers     : 6
      ins           : 2
      outs          : 2
      insns size    : 56 16-bit code units
      catches       : (none)
      positions     :
        0x0001 line=14
        0x0004 line=15
        0x000a line=16
        0x0019 line=17
        0x0028 line=18
        0x0030 line=20
        0x0031 line=16
        0x0034 line=17
      locals        :
        0x001a - 0x0031 reg=0 fab Landroid/support/design/widget/FloatingActionButton;
        0x0034 - 0x0038 reg=0 fab Landroid/support/design/widget/FloatingActionButton;
        0x0000 - 0x0038 reg=4 this Lorg/somesuch/projectname/ProjectsActivity;
        0x0000 - 0x0038 reg=5 savedInstanceState Landroid/os/Bundle;
  source_file_idx   : 492 (/Users/bbousquet/Documents/somesuch.org/experimental/ProjectName/ProjectName (Android)/ProjectsActivity.swift)

It seems to be. The app begins launching and then poofs. I am watching Logcat in Android Studio as Fire seems oblivious to what’s happening in this case.

Ok, so the class seems to be there, id say the exceptions are probably misleading then. is there nothing else isn logcat (which btw also shows in Fire, third tab in the debug console) when the app crashes? usually there’s an explicit exception and call stack…

No. What’s being shown in Logcat is pretty much the same thing I’ve pasted in the original post.

Hmm. logcat should be spewing out a billion lines of stuff per second, not just this one message. sure it’s it being filtered? try running raw add logcat in terminal.

PM’ing the non filtered log to you.

it seems like the real issue is

2018-11-16 10:42:53.643 17421-17421/? I/ncontrols.focu: The ClassLoaderContext is a special shared library. 2018-11-16 10:42:53.819 17421-17421/? I/ncontrols.focu: Rejecting re-init on previously-failed class java.lang.Class<android.support.v7.app.AppCompatActivity>: java.lang.NoClassDefFoundError: Failed resolution of: Landroid/support/v4/app/FragmentActivity;

?

are your package references set to copy local?

They all show Copy Local next to them, yes.