apk文件不包含java文件 [英] apk file does not contain the java file
问题描述
E / AndroidRuntime(3069):java.lang.RuntimeException:无法实例化活动ComponentInfo {fun.n.games/fun.n.games.HelloActivity}:java.lang.ClassNotFoundException:未在路径中找到类fun.n.games.HelloActivity:DexPathList [[zip文件/ 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;
导入android.app.Activity;
导入android.os.Bundle;
导入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.0encoding =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>
< category android:name =android.intent.category.LAUNCHER/>
< / intent-filter>
< / activity>
< / application>
< / manifest>
这是由一个build.gradle构建的
buildscript {
//使用jcenter存储库下载依赖关系
存储库{
jcenter()
}
依赖关系{
classpath'com.android.tools.build:gradle:2.2.3'
}
}
apply plugin:'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion25.0.2
}
code>
我在命令提示符下使用gradle来构建和安装
$ gradle installDebug
除了在开始时的错误发布时,当我搜索build文件夹时,我没有看到我期待的HelloActivity.class。
如何获取java类以添加到apk文件中? c> with android:name =。HelloActivity
Am getting the following error
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]]
This error shows up when I try to execute my android app that I have installed on my AVD.
My AVD is running as follows
$ emulator -avd Nexus_S_API_22
The code for the HelloActivity is present.
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!");
}
}
It is being pulled together by the following manifest file.
<?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>
This is being built by a single 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"
}
And I am using gradle from command prompt to build and install
$ gradle installDebug
Apart from the error at the beginning of the post, when I search through the build folder, I don't see the HelloActivity.class that I was expecting there.
How do I get the java class to get added to the apk file?
Replace android:name="fun.n.games.HelloActivity"
with android:name=".HelloActivity"
这篇关于apk文件不包含java文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!