无法从jar

时间:2015-07-07 19:53:49

标签: java android maven runtimeexception library-project

当重新启动我的旧项目时,我正在努力解决奇怪的问题。

我有两个项目:

  • 提供扩展标准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]]

之前很少有信息"只需修复清单"评论:)

  • 当它是一个Android应用程序(一个项目)时,一切正常。

  • 当MainActivity从提供的jar文件(它扩展Activity的抽象类)扩展CatEngineActivity类时,应用程序崩溃。

  • 当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

1 个答案:

答案 0 :(得分:0)

您能否在MainActivity&amp;中提供代码? CatEngineActivity?

我怀疑CatEngineActivity使用xml布局文件作为setContentView()?如果是这样,那么原因是因为android资源没有打包在你的jar文件中。您必须将CatEngineActivity打包为AAR文件,该文件将包含您的Android资源。

如果是这样,请在AAR上试用这个入门套件,看看它是否有帮助。您可以忽略上传到bintray。

https://github.com/jimcoven/android-bintray-kit