简体   繁体   English

应用程序不是从清单中的预期类开始

[英]Application not starting from expected class in manifest

I'm totally new with Android Studio and I'm trying to port a working project I had in Eclipse ADT. 我对Android Studio完全陌生,并且试图移植我在Eclipse ADT中拥有的工作项目。

It's an app (ArchPanoViewer) which depends on two libraries: Zxing _which is "captureActivity" in the _ and PanoramaGL "lib_panorama". 这是一个应用程序(ArchPanoViewer),它依赖于两个库:Zxing _(在_中为“ captureActivity”)和PanoramaGL“ lib_panorama”。 The scope of the app is to show a dialog window at the beginning, then when you press a button the barcode scanner is launched (MainActivity.java) and then the retrieved image through QRcode is shown in a panorama view (PanoramaActivity.java). 该应用程序的范围是在开始时显示一个对话框窗口,然后当您按下按钮时,条形码扫描器将启动(MainActivity.java),然后通过QRcode检索到的图像将显示在全景视图(PanoramaActivity.java)中。

This is the generical project structure: 这是通用的项目结构:

ArchPanoViewer
|_ app
     |_com.example.admin.archpanoviewer
         |_MainActivity.java
         |_PanoramaActivity.java
|_captureActivity
|_lib_panorama

I have a starting class inside app folder named: MainActivity.java . 我的应用程序文件夹中有一个起始类,名为MainActivity.java。

Here is the manifest file for "app" that I was using when programming with Eclipse: 这是我在使用Eclipse编程时使用的“ app”清单文件:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.admin.archpanoviewer"
xmlns:tools="http://schemas.android.com/tools">

<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.FLASHLIGHT" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.WRITE_SETTINGS" />

<application
    android:allowBackup="true"
    android:label="@string/app_name"
    tools:replace="icon"
    android:icon="@drawable/ic_launcher"
    android:theme="@style/AppTheme" >


<activity
    android:name="com.example.admin.archpanoviewer.MainActivity"
    android:configChanges="orientation|screenSize" >
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>

<activity
    android:name="com.google.zxing.client.android.CaptureActivity"
    android:screenOrientation="landscape"
    android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
    android:windowSoftInputMode="stateAlwaysHidden" >

    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.DEFAULT" />
    </intent-filter>    //this part was deleted according to suggestions 

    <intent-filter>
        <action android:name="com.google.zxing.client.android.SCAN" />
        <category android:name="android.intent.category.DEFAULT" />
    </intent-filter>
</activity>

<activity
    android:name="com.example.admin.archpanoviewer.PanoramaActivity"
    android:parentActivityName="com.example.admin.archpanoviewer.MainActivity"
    android:configChanges="orientation" >
    <meta-data
        android:name="android.support.PARENT_ACTIVITY"
        android:value="com.example.admin.archpanoviewer.MainActivity" />
</activity>

</application>

The problem in Android Studio is that the MainActivity.java is completely skipped and the application is launched as a simple Barcode scanner that retrieves QR and that's it. Android Studio中的问题是MainActivity.java被完全跳过,并且该应用程序作为一个简单的条形码扫描仪启动,该扫描仪检索QR就是这样。 It's not considering at all the workflow written in the classes. 它根本没有考虑类中编写的工作流程。

Where can I specify the starting point of the application?? 在哪里可以指定应用程序的起点? For sure there is a conflict somewhere as 2 icons appear in the app drawer.. Thanks in advance! 确保在某些地方存在冲突,因为应用程序抽屉中会出现2个图标。

PS I don't know if they are useful. PS我不知道它们是否有用。 But here there are also the build.gradles: 但是这里也有build.gradles:

build.gradle (whole project): build.gradle(整个项目):

 buildscript {
repositories {
    jcenter()
}
dependencies {
    classpath 'com.android.tools.build:gradle:1.0.0'

    // NOTE: Do not place your application dependencies here; they belong
    // in the individual module build.gradle files
}
}

allprojects {
repositories {
    jcenter()
}
}

build.gradle (app): build.gradle(应用程序):

apply plugin: 'com.android.application'

android {
compileSdkVersion 21
buildToolsVersion "21.1.2"

defaultConfig {
    applicationId "com.example.admin.archpanoviewer"
    minSdkVersion 8
    targetSdkVersion 21
    versionCode 1
    versionName "1.0"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
}

 dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.3'
compile project(':lib_panorama')
compile project(':captureActivity')
 }

build.gradle (Zxing) build.gradle(Zxing)

apply plugin: 'com.android.library'
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"

defaultConfig {
    minSdkVersion 7
    targetSdkVersion 21
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_7
        targetCompatibility JavaVersion.VERSION_1_7
    }
}

buildTypes {
    release {
        minifyEnabled true
        proguardFiles 'proguard-android-optimize.txt'
    }
}
}

dependencies {
}

build.gradle (PanoramaGL) build.gradle(PanoramaGL)

apply plugin: 'java'

dependencies {
compile files('libs/commons-httpclient-3.1.jar')
compile files('libs/android.jar')

} }

I didn't manage to import Zxing as a simple library as panoramaGL.. I had method errors so I gave up. 我没有将Zxing作为一个简单的库(如PanoramaGL)导入。我遇到了方法错误,因此放弃了。 I hope this is not the problem. 我希望这不是问题。

EDIT 1 编辑1

According to suggestions I doublechecked the manifest (updates highlighted above) and discovered this line in the running app window: 根据建议,我仔细检查了清单(上面突出显示的更新),并在正在运行的应用程序窗口中发现了这一行:

 Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.example.admin.prova/com.google.zxing.client.android.CaptureActivity }

but CaptureActivity is not set as launcher.. 但CaptureActivity未设置为启动器。

Consider this xml part 考虑这个xml部分

<activity
    android:name="com.example.admin.archpanoviewer.MainActivity"
    android:configChanges="orientation|screenSize" >
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />   <-------Here
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>

The activity you want to start with must have MAIN here,otherwise put DEFAULT here 您要开始的活动必须在这里有MAIN ,否则将DEFAULT放在这里

Basically Intents are a way of interactivity communication in Android. 基本上,意图是Android中互动交流的一种方式。

Whenever an intent is fired, it is taken up by some-activity which was expecting this Intent and that activity responds to the intent. 每当触发意图时,它就会被某个预期该意图的活动占用,而该活动会对该意图做出响应。

Now, how does Android-runtime tells your Application's activity to start ? 现在,Android运行时如何告诉您的应用程序活动开始? Well... by firing an Intent. 好吧...发射一个意图。

Basically, This intents is fired to start main activity of an application. 基本上,触发此意图是为了启动应用程序的主要活动。

<action android:name="android.intent.action.MAIN" />

So... only your main-activity should be listening to this intent. 所以...只有您的主要活动在听这个意图。

In your app... all activities are listening to these intents... which means "As far as they know... all of these are main activities." 在您的应用中,所有活动都在听这些意图……这意味着“据他们所知……所有这些都是主要活动。”

Also... Only the launcher-activity should handle intents of this category. 另外...仅启动器活动应处理此类别的意图。

<category android:name="android.intent.category.LAUNCHER" /> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM