【发布时间】:2015-07-07 19:53:48
【问题描述】:
重新启动我的旧项目时,我遇到了奇怪的问题。
我有两个项目:
- 提供扩展标准 Activity 的类的库。
- 应使用上述类作为启动活动的应用程序。
当我尝试启动应用程序时遇到错误:
java.lang.RuntimeException:
Unable to instantiate activity ComponentInfo{org.bsoftware.catengine.example/org.bsoftware.catengine.example.MainActivity}:
java.lang.ClassNotFoundException:
Didn't find class "org.bsoftware.catengine.example.MainActivity" on path:
DexPathList[[zip file "/data/app/org.bsoftware.catengine.example-1/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
“只需修复清单”cmets 之前的信息很少 :)
当它是一个 android 应用程序(一个项目)时,一切正常。
当 MainActivity 从提供的 jar 文件扩展 CatEngineActivity 类(它是扩展 Activity 的抽象类)时应用程序崩溃。
- 当 MainActivity 从标准 android lib 扩展 Activity 时,应用程序不会崩溃。
您知道在这种情况下出了什么问题吗?
库项目 pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.bsoftware.catengine</groupId>
<artifactId>cat-engine-core</artifactId>
<version>0.1.0</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>
<dependencies>
<dependency>
<groupId>com.google.android</groupId>
<artifactId>android</artifactId>
<version>4.1.1.4</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
库项目清单:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="eu.catengine.activity"
android:versionCode="1"
android:versionName="1.0.0" >
</manifest>
应用 pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>eu.catengine</groupId>
<artifactId>game-example</artifactId>
<version>0.1.0</version>
<properties>
<!-- use UTF-8 for everything -->
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>
<dependencies>
<dependency>
<groupId>com.google.android</groupId>
<artifactId>android</artifactId>
<version>4.1.1.4</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.bsoftware.catengine</groupId>
<artifactId>cat-engine-core</artifactId>
<version>0.1.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>com.jayway.maven.plugins.android.generation2</groupId>
<artifactId>android-maven-plugin</artifactId>
<version>3.9.0-rc.1</version>
<configuration>
<sdk>
<platform>19</platform>
</sdk>
<deleteConflictingFiles>true</deleteConflictingFiles>
<undeployBeforeDeploy>true</undeployBeforeDeploy>
</configuration>
<extensions>true</extensions>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
应用清单:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.bsoftware.catengine.example"
android:versionCode="1"
android:versionName="1.0.0" >
<application android:label="@string/app_name" >
<activity
android:name=".MainActivity"
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>
我也试过完整的包路径:
android:name="org.bsoftware.catengine.example.MainActivity"
可在此处找到概念证明: https://github.com/mbienkowski/problems/tree/feature/001
【问题讨论】:
标签: java android maven runtimeexception library-project