Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/206.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 无法从jar中给定的扩展活动启动活动_Java_Android_Maven_Runtimeexception_Library Project - Fatal编程技术网

Java 无法从jar中给定的扩展活动启动活动

Java 无法从jar中给定的扩展活动启动活动,java,android,maven,runtimeexception,library-project,Java,Android,Maven,Runtimeexception,Library Project,当我重新启动一个旧项目时,我遇到了一个奇怪的问题 我有两个项目: 提供扩展标准活动的类的库 应使用所述类作为起始活动的应用程序 当我尝试启动应用程序时,遇到一个错误: java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{org.bsoftware.catengine.example/org.bsoftware.catengine.example.MainActivity}: java.lang.

当我重新启动一个旧项目时,我遇到了一个奇怪的问题

我有两个项目:

  • 提供扩展标准活动的类的库
  • 应使用所述类作为起始活动的应用程序
当我尝试启动应用程序时,遇到一个错误:

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文件(扩展活动的抽象类)扩展CatEngineActivity类时,应用程序崩溃

  • 当MainActivity从标准android库扩展活动时,应用程序不会崩溃
你知道这个案子出了什么问题吗

库项目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>


可在此处找到概念证明:

能否在MainActivity&CatEngineActivity中提供代码

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

如果是这样,在AAR上试试这个初学者工具包,看看它是否有帮助。您可以忽略上传到收件箱的操作


能否在MainActivity&CatEngineActivity中提供代码

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

如果是这样,在AAR上试试这个初学者工具包,看看它是否有帮助。您可以忽略上传到收件箱的操作


在我的例子中,setContentView()不使用xml文件,它使用GLSurfaceView来呈现OpenGL视图。我现在不在家。稍后我将添加一些代码:)抱歉,等待。。我刚刚编辑了第一篇文章,并用一个小项目添加了到github的链接。我把你们的回购协议分叉,并修复了它。该库存在一些命名空间问题,在至少为其提供了一个受保护的访问修饰符后,loadCreate方法被正确调用。看看只需使用AndroidStudio打开解决方案项目。遗憾的是,它对我不起作用。我在运行时仍然遇到同样的错误。无论如何,我有一个临时解决方案,它将我的lib项目打包为libapk。对于每个人:只需谷歌apklib maven示例,您就会得到它;)在我的例子中,setContentView()不使用xml文件,它使用GLSurfaceView来呈现OpenGL视图。我现在不在家。稍后我将添加一些代码:)抱歉,等待。。我刚刚编辑了第一篇文章,并用一个小项目添加了到github的链接。我把你们的回购协议分叉,并修复了它。该库存在一些命名空间问题,在至少为其提供了一个受保护的访问修饰符后,loadCreate方法被正确调用。看看只需使用AndroidStudio打开解决方案项目。遗憾的是,它对我不起作用。我在运行时仍然遇到同样的错误。无论如何,我有一个临时解决方案,它将我的lib项目打包为libapk。对于每个人:只需谷歌apklib maven示例,您就会得到它;)
<?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"