【发布时间】:2017-04-15 07:54:50
【问题描述】:
我收到以下错误
E/AndroidRuntime( 3069): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{fun.n.games/fun.n.games.HelloActivity}: java.lang.ClassNotFoundException: Didn't find class "fun.n.games.HelloActivity" on path: DexPathList[[zip file "/data/app/fun.n.games-1/base.apk"],nativeLibraryDirectories=[/vendor/lib64, /system/lib64]]
当我尝试执行我在 AVD 上安装的 android 应用程序时出现此错误。
我的 AVD 运行如下
$ emulator -avd Nexus_S_API_22
HelloActivity 的代码已存在。
package fun.n.games;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class HelloActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.hello_layout);
}
@Override
public void onStart() {
super.onStart();
TextView textView = (TextView) findViewById(R.id.text_view);
textView.setText("Hello world!");
}
}
它被以下清单文件拉到一起。
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="fun.n.games"
android:versionCode="1"
android:versionName="1.0.0" >
<application android:label="@string/app_name" >
<activity
android:name="fun.n.games.HelloActivity"
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>
这是由单个 build.gradle 构建的
buildscript {
// use the jcenter repository to download the dependencies
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.3'
}
}
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
}
我在命令提示符下使用 gradle 来构建和安装
$ gradle installDebug
除了文章开头的错误之外,当我搜索构建文件夹时,我没有看到我期待的 HelloActivity.class。
如何将 java 类添加到 apk 文件中?
【问题讨论】:
-
尝试禁用即时运行
-
我没有使用 AndroidStudio。如何从命令提示符禁用即时运行?