gpt4 book ai didi

java.lang.RuntimeException : Unable to start activity ComponentInfo when using admob sdk

转载 作者:行者123 更新时间:2023-12-02 04:01:03 24 4
gpt4 key购买 nike

我很确定这与 Theme.AppCompat 无关,因为启用 proguard 的应用程序最初在没有 com.google.android.gms:play-services- 的情况下也能正常运行ads:7.5.0,添加 com.google.android.gms:play-services-ads:7.5.0 后出现问题。

包含 com.google.android.gms:play-services-ads 后,它仅在禁用 proguard 时有效。

有人可以帮忙吗?我真的很讨厌java无法保护源代码,并且希望我永远不会使用proguard。

错误堆栈

FATAL EXCEPTION: main java.lang.RuntimeException: Unable to start activity ComponentInfo{com.company.project/com.company.project.MainActivity}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity. at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2463) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2520) at android.app.ActivityThread.access$600(ActivityThread.java:162) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1366) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:158) at android.app.ActivityThread.main(ActivityThread.java:5751) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:511) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1083) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:850) at dalvik.system.NativeStart.main(Native Method) Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity. at android.support.v7.a.ae.q(Unknown Source) at android.support.v7.a.ae.p(Unknown Source) at android.support.v7.a.ae.a(Unknown Source) at android.support.v7.a.u.setContentView(Unknown Source) at com.company.project.MainActivity.onCreate(Unknown Source) at android.app.Activity.performCreate(Activity.java:5165) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1103) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2419) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2520)  at android.app.ActivityThread.access$600(ActivityThread.java:162)  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1366)  at android.os.Handler.dispatchMessage(Handler.java:99)  at android.os.Looper.loop(Looper.java:158)  at android.app.ActivityThread.main(ActivityThread.java:5751)  at java.lang.reflect.Method.invokeNative(Native Method)  at java.lang.reflect.Method.invoke(Method.java:511)  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1083)  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:850)  at dalvik.system.NativeStart.main(Native Method)

Gradle :

android {
compileSdkVersion 23
buildToolsVersion "23.0.2"

defaultConfig {
applicationId "com.company.project"
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
debug {
// proguard enabled for debug
minifyEnabled true
FileCollection proGuardFileCollection = files { file('./proguard').listFiles() }
proguardFiles(proGuardFileCollection)
proguardFiles getDefaultProguardFile('proguard-android.txt')
}
release {
minifyEnabled true
FileCollection proGuardFileCollection = files { file('./proguard').listFiles() }
proguardFiles(proGuardFileCollection)
proguardFiles getDefaultProguardFile('proguard-android.txt')

}
}
}

dependencies {
compile project(':vitamio')
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:design:23.1.1'
compile 'com.facebook.fresco:fresco:0.8.1'
compile 'com.loopj.android:android-async-http:1.4.9'
compile 'in.srain.cube:ultra-ptr:1.0.11'
compile 'in.srain.cube:grid-view-with-header-footer:1.0.12'

compile 'com.google.android.gms:play-services-ads:7.5.0'

compile('com.crashlytics.sdk.android:crashlytics:2.5.5@aar') {
transitive = true;
}

}

buildscript {
repositories {
maven { url 'https://maven.fabric.io/public' }
}

dependencies {
classpath 'io.fabric.tools:gradle:1.+'
}
}

apply plugin: 'com.android.application'

apply plugin: 'io.fabric'
repositories {
maven { url 'https://maven.fabric.io/public' }
}

AndroidManifes.xml:

<application
android:allowBackup="true"
android:icon="@mipmap/logo"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">

<!-- note: @style/AppTheme is defined as
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
-->

<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".VideoPlayerActivity" android:theme="@style/AppTheme.NoActionBar"/>
<activity android:name=".VideoActivity" android:theme="@style/AppTheme.NoActionBar"/>

<!--AdMob-->
<meta-data android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version"/>
<activity android:name="com.google.android.gms.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
android:theme="@android:style/Theme.Translucent" />


</application>

Admob 的 Proguard(从 gi​​thub 上的 admob 示例复制):

# For Google Play Services
-keep public class com.google.android.gms.ads.**{
public *;
}

# For old ads classes
-keep public class com.google.ads.**{
public *;
}

# For mediation
#-keepattributes *Annotation*

# Other required classes for Google Play Services
# Read more at http://developer.android.com/google/play-services/setup.html
-keep class * extends java.util.ListResourceBundle {
protected Object[][] getContents();
}

-keep public class com.google.android.gms.common.internal.safeparcel.SafeParcelable {
public static final *** NULL;
}

-keepnames @com.google.android.gms.common.annotation.KeepName class *
-keepclassmembernames class * {
@com.google.android.gms.common.annotation.KeepName *;
}

-keepnames class * implements android.os.Parcelable {
public static final ** CREATOR;
}

最佳答案

以下是您在 admob 的 proguard 规则中需要的内容:

-keep class com.google.android.gms.common.GooglePlayServicesUtil {*;}
-keep class com.google.android.gms.ads.identifier.AdvertisingIdClient {*;}
-keep class com.google.android.gms.ads.identifier.AdvertisingIdClient$Info {*;}

-keep class com.google.android.gms.** { *; }
-dontwarn com.google.android.gms.**
-keep class com.google.ads.** {*;}

检查是否缺少任何内容或仅添加所有内容(没有区别),然后检查您的应用是否正常工作。

另外,您的 Activity java 文件扩展的是哪个类,如果它扩展的是 ActionBarActivity,请将其更改为 Activity

关于java.lang.RuntimeException : Unable to start activity ComponentInfo when using admob sdk,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34892633/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com