我刚刚创建了一个包含单个活动的全新Android项目。
清单:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="de.foo.bar">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme">
<activity
android:name="de.foo.bar.MainActivity"
android:label="@string/app_name"
android:launchMode="singleTop">
</activity>
</application>
</manifest>
摇篮:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.0"
defaultConfig {
applicationId "de.foo.bar"
minSdkVersion 16
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.0.0'
compile 'com.android.support:design:23.0.0'
}
当我刚建立项目时,不会出现错误。但是,当我尝试在设备上运行它时,我得到以下错误:
插件Android支持中的异常:
null
java.lang.AssertionError
at org.jetbrains.android.run.DefaultActivityLocator.getQualifiedActivityName(DefaultActivityLocator.java:48)
at org.jetbrains.android.run.AndroidActivityLauncher.launch(AndroidActivityLauncher.java:95)
at org.jetbrains.android.run.AndroidRunningState.doPrepareAndStart(AndroidRunningState.java:855)
at org.jetbrains.android.run.AndroidRunningState.prepareAndStartApp(AndroidRunningState.java:810)
at org.jetbrains.android.run.AndroidRunningState.prepareAndStartAppWhenDeviceIsOnline(AndroidRunningState.java:771)
at org.jetbrains.android.run.AndroidRunningState.doStart(AndroidRunningState.java:603)
at org.jetbrains.android.run.AndroidRunningState.start(AndroidRunningState.java:579)
at org.jetbrains.android.run.AndroidRunningState$2.run(AndroidRunningState.java:310)
at com.intellij.openapi.application.impl.ApplicationImpl$8.run(ApplicationImpl.java:400)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:439)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
at java.util.concurrent.FutureTask.run(FutureTask.java:138)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918)
at java.lang.Thread.run(Thread.java:695)
at org.jetbrains.ide.PooledThreadExecutor$1$1.run(PooledThreadExecutor.java:56)
任何想法是什么问题?我正在使用android studio 1.4。
答案 0 :(得分:2)
我认为它崩溃是因为Android Studio无法找到默认/启动器活动,这是因为Android Studio需要定义默认活动,您可以这样做,为您的清单添加intent-filter。 / p>
您在AndroidManifest上的活动条目应如下所示:
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme">
<activity
android:name="de.foo.bar.MainActivity"
android:label="@string/app_name"
android:launchMode="singleTop">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
您可以在没有intent-filter的情况下进行活动,但至少需要一个具有此过滤器的活动。
答案 1 :(得分:0)
当我尝试为我的项目生成签名的APK时,我遇到了同样的问题,因此解决方法是在项目的build.gradle文件中添加它:
Prefs preferences = Prefs.getInstance(getApplicationContext());
if(preferences.getBoolean("sendMail")
{
// .... send email
}