0

When I create a blank activity in Android Studio 2.0 and try to run it on API 16 it compiles without errors. When I run it on an emulator with API 23 it runs without errors. When I run it on API 16 it gives me a bunch of errors when the app starts. See below. The weird thing is that the app runs OK.

What can be the cause of this?

In Android Studio I invalidated and cleared the cache. Also cleaned the project and rebuilt it.

For reference the code:

AndroidManifest.xml

    <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="nl.myapp.test">
    <application
        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>
    </application>

MainActivity.Java

package nl.myapp.test;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }
}

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="nl.myapp.test.MainActivity">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello World!" />
</RelativeLayout>

Gradle 2.0.0 build file build.gradle (Module App)

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.3"

    defaultConfig {
        applicationId "nl.myapp.test"
        minSdkVersion 16
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.3.0'
}

The logcat errors when the app starts on API 16

04-10 18:29:29.945 23899-23899/nl.myapp.test E/dalvikvm: Could not find class 'android.app.ActivityManager$TaskDescription', referenced from method nl.myapp.test.MainActivity.access$super
04-10 18:29:29.945 23899-23899/nl.myapp.test E/dalvikvm: Could not find class 'android.os.UserHandle', referenced from method nl.myapp.test.MainActivity.access$super
04-10 18:29:29.945 23899-23899/nl.myapp.test E/dalvikvm: Could not find class 'android.os.UserHandle', referenced from method nl.myapp.test.MainActivity.access$super
04-10 18:29:29.945 23899-23899/nl.myapp.test E/dalvikvm: Could not find class 'android.app.SharedElementCallback', referenced from method nl.myapp.test.MainActivity.access$super
04-10 18:29:29.945 23899-23899/nl.myapp.test E/dalvikvm: Could not find class 'android.os.PersistableBundle', referenced from method nl.myapp.test.MainActivity.access$super
04-10 18:29:29.945 23899-23899/nl.myapp.test E/dalvikvm: Could not find class 'android.transition.TransitionManager', referenced from method nl.myapp.test.MainActivity.access$super
04-10 18:29:29.945 23899-23899/nl.myapp.test E/dalvikvm: Could not find class 'android.app.SharedElementCallback', referenced from method nl.myapp.test.MainActivity.access$super
04-10 18:29:29.945 23899-23899/nl.myapp.test E/dalvikvm: Could not find class 'android.os.UserHandle', referenced from method nl.myapp.test.MainActivity.access$super
04-10 18:29:29.945 23899-23899/nl.myapp.test E/dalvikvm: Could not find class 'android.os.UserHandle', referenced from method nl.myapp.test.MainActivity.access$super
04-10 18:29:29.945 23899-23899/nl.myapp.test E/dalvikvm: Could not find class 'android.app.assist.AssistContent', referenced from method nl.myapp.test.MainActivity.access$super
04-10 18:29:29.945 23899-23899/nl.myapp.test E/dalvikvm: Could not find class 'android.view.SearchEvent', referenced from method nl.myapp.test.MainActivity.access$super
04-10 18:29:29.945 23899-23899/nl.myapp.test E/dalvikvm: Could not find class 'android.os.UserHandle', referenced from method nl.myapp.test.MainActivity.access$super
04-10 18:29:29.945 23899-23899/nl.myapp.test E/dalvikvm: Could not find class 'android.os.PersistableBundle', referenced from method nl.myapp.test.MainActivity.access$super
Peter O.
  • 32,158
  • 14
  • 82
  • 96
tvdpol
  • 198
  • 2
  • 13
  • 3
    Just a friendly tip, you may want to read over this page: [The How-To-Ask Guide](https://stackoverflow.com/help/how-to-ask) so you can always be sure that your questions are easily answerable and as clear as possible. Be sure to include any efforts you've made to fix the problem you're having, and what happened when you attempted those fixes. Also don't forget to your show code and any error messages! – rsjaffe Apr 10 '16 at 16:45

2 Answers2

2

It could be that your app is hitting the 64k methods limit. The issue would be seen from API level 21 and below for your app. Refer the document. It gives details about the problem and how you can use Multidex Support Library to resolve it for older versions of Android.

Also this could be a quick solution of the problem.

Community
  • 1
  • 1
Bharath Kumar
  • 541
  • 3
  • 10
  • That really helped me, thanks! I've referenced to your answer from a similar question, and added some additional useful information, over [here](https://stackoverflow.com/questions/37998266/android-studio-many-error-could-not-find-class-android-xxx#38666791) – P Kuijpers Jul 29 '16 at 20:20
1

In Android Studio I went to File -> Project Structure -> Project.

First I upgraded Gradle to 2.11 and the Android Plugin Version to 2.0.0. Next I synced the project and compiled it. The errors were still there.

After this I downgraded the Android Plugin Version to 1.5.0.

Now when I compile and run the project the errors are gone.

tvdpol
  • 198
  • 2
  • 13
  • 1
    why is that ? its working on 5.1 emulator (genymotion) and not on a 4.4 kitkat tablet. Is theres some specific gradle requirements on lollipop above ? – ralphgabb Jun 30 '16 at 04:29