MuntashirAkon/AppManager · error · ClassNotFoundException

{className} could not be found.

Error message

{className} could not be found.

What it means

getClassDef(className) looks up a dexlib2 ClassDef from the map built when DexClasses was constructed. If the requested class name isn't present in any of the loaded dex files — wrong class name, class in a dex that wasn't loaded, or the name needs a different format (e.g. L-com/example/Foo; internal form vs dotted) — it throws ClassNotFoundException(className + ' could not be found.').

Source

Thrown at app/src/main/java/io/github/muntashirakon/AppManager/dex/DexClasses.java:142

            mOptions.inlineResolver = InlineMethodResolver.createInlineMethodResolver(
                    ((DexBackedOdexFile) dexFile).getOdexVersion());
        }
    }

    @NonNull
    public List<String> getClassNames() {
        return new ArrayList<>(mClassNameClassDefMap.keySet());
    }

    @NonNull
    public List<String> getBaseClassNames() {
        return new ArrayList<>(mBaseClassNestedClassMap.keySet());
    }

    @NonNull
    public ClassDef getClassDef(@NonNull String className) throws ClassNotFoundException {
        ClassDef classDef = mClassNameClassDefMap.get(className);
        if (classDef == null) throw new ClassNotFoundException(className + " could not be found.");
        return classDef;
    }

    @NonNull
    public String getJavaCode(@NonNull String className) throws ClassNotFoundException {
        try {
            String baseClass = DexUtils.getClassNameWithoutInnerClasses(className);
            List<String> classes = mBaseClassNestedClassMap.get(baseClass);
            if (classes == null || classes.isEmpty() || !classes.contains(className)) {
                throw new ClassNotFoundException();
            }
            List<ClassDef> classDefs = new ArrayList<>(classes.size());
            for (String cls : classes) {
                classDefs.add(getClassDef(cls));
            }
            return DexUtils.toJavaCode(classDefs, mOpcodes);
        } catch (IOException e) {
            throw new ClassNotFoundException(e.getMessage(), e);

View on GitHub (pinned to 0152f468fc)

Solutions

  1. Convert the class name to smali/internal form (Lcom/example/Foo;) before lookup, or normalize both sides
  2. Check getClassList()/the class-tree for the actual (possibly obfuscated) name and use that
  3. Load all dex files containing the target class (splits, dynamic features) into DexClasses
  4. Verify the class exists in the APK's dex (e.g. via dexdump) and wasn't removed by R8/ProGuard

Example fix

// before
dexClasses.getJavaCode("com.example.Foo"); // ClassNotFoundException
// after
String smaliName = "L" + "com.example.Foo".replace('.', '/') + ";";
if (dexClasses.getClassList().contains(smaliName)) {
    dexClasses.getJavaCode(smaliName);
} else {
    throw new ClassNotFoundException(smaliName + " not in loaded dex files");
}
Defensive patterns

Strategy: try-catch

Validate before calling

boolean present = dexClasses.getClassList().contains(toSmaliName(className));
static String toSmaliName(String cn) { return "L" + cn.replace('.', '/') + ";"; }

Type guard

boolean hasClass(DexClasses dc, String cn) {
    return dc.getClassList().contains("L" + cn.replace('.', '/') + ";");
}

Try / catch

try {
    ClassDef def = dexClasses.getClassDef(smaliName);
} catch (ClassNotFoundException e) {
    Log.w(TAG, "Class not in loaded dex (obfuscated or in another split?)", e);
}

Prevention

When it happens

Trigger: Calling getClassDef/getJavaCode/getClassContents/buildTree with a class name that is absent from mClassNameClassDefMap: misspelled name, class lives in a dynamic feature/other dex file not passed to the constructor, name passed in dotted ('com.example.Foo') while the map is keyed by smali-style 'Lcom/example/Foo;', or ProGuard/R8 renamed/removed the class.

Common situations: Reflecting on an obfuscated release APK where the class was renamed (a.b.c) or stripped; looking up a class from a split APK whose dex wasn't loaded; using the wrong name format after copying from Java source.

Related errors


AI-assisted analysis of MuntashirAkon/AppManager@0152f468fc (2026-09-12). Data as JSON: /api/errors/e4073b97d693b2a1. Report an issue: GitHub.