应用在运行名为

时间:2018-09-04 04:26:23

标签: java android android-gradle

我从事一个项目已经很长时间了。 最近,我开始在应用程序启动时遇到ANR问题。 实际上,由于从未调用App.onCreate()方法,因此应用程序甚至无法启动。据我所知,在此之前唯一被调用的是任何onCreate()的{​​{1}}方法。所以我从清单文件中删除了它们,但问题仍然存在。 App。ContentProvider仍未调用。

以下是一些其他详细信息:

清单文件:

onCreate

应用gradle文件:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.somepackagename">

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.RECORD_AUDIO" />
    <uses-permission android:name="android.permission.CAMERA" />

    <uses-feature
        android:name="android.hardware.camera"
        android:required="true" />
    <uses-feature
        android:glEsVersion="0x00020000"
        android:required="true"/>

    <application
        android:name=".App"
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <meta-data
            android:name="com.facebook.sdk.ApplicationId"
            android:value="@string/facebook_app_id" />
        <meta-data
            android:name="io.fabric.ApiKey"
            android:value="a_very_long_secret_key" />
        <meta-data
            android:name="com.google.android.geo.API_KEY"
            android:value="another_secret_key" />

        <meta-data
            android:name="com.google.firebase.messaging.default_notification_icon"
            android:resource="@mipmap/ic_launcher" />

        <meta-data
            android:name="com.google.firebase.messaging.default_notification_color"
            android:resource="@color/colorPrimary" />

        <activity
            android:name=".activities.SplashActivity"
            android:configChanges="keyboardHidden|orientation"
            android:label="@string/app_name"
            android:screenOrientation="portrait">

            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>

            <intent-filter android:autoVerify="true">
                <action android:name="android.intent.action.VIEW" />

                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />

                <data
                    android:host="@string/deep_link_host"
                    android:scheme="https" />
            </intent-filter>
        </activity>
        <activity
            android:name=".activities.MainActivity"
            android:screenOrientation="portrait">
        </activity>
        <activity
            android:name=".activities.MessageCreationEditActivity"
            android:screenOrientation="portrait" />
        <activity
            android:name=".activities.SignInSignUpActivity"
            android:screenOrientation="portrait"
            android:windowSoftInputMode="adjustResize"/>
        <activity
            android:name=".activities.SettingsActivity"
            android:screenOrientation="portrait"/>
        <activity
            android:name=".activities.MediaViewer"
            android:configChanges="orientation|screenSize"/>
        <activity
            android:name=".activities.CreateGroupActivity"
            android:screenOrientation="portrait"
            android:windowSoftInputMode="adjustPan" />
        <activity
            android:name=".activities.CategoriesActivity"
            android:screenOrientation="portrait" />
        <activity
            android:name=".activities.ExploreActivity"
            android:screenOrientation="portrait" />
        <activity
            android:name=".activities.AllMembersActivity"
            android:screenOrientation="portrait" />
        <activity
            android:name=".activities.InviteMembersActivity"
            android:screenOrientation="portrait" />
        <activity
            android:name=".activities.QrCodeActivity"
            android:screenOrientation="portrait" />
        <activity
            android:name=".activities.GroupSettingsActivity"
            android:screenOrientation="portrait" />
        <activity
            android:name=".activities.SliceCreationEditActivity"
            android:screenOrientation="portrait" />
        <activity
            android:name=".activities.FavoritesMessagesActivity"
            android:screenOrientation="portrait" />
        <activity
            android:name=".activities.QrCodeScannerActivity"
            android:screenOrientation="portrait" />
        <activity
            android:name=".activities.UserDetailsActivity"
            android:screenOrientation="portrait" />
        <activity
            android:name=".activities.MembershipActivity"
            android:screenOrientation="portrait" />
        <activity
            android:name=".activities.GroupDetailsActivity"
            android:screenOrientation="portrait"/>
        <activity
            android:name=".activities.MemberManagementActivity"
            android:screenOrientation="portrait" />
        <activity
            android:name=".activities.ReportActivity"
            android:screenOrientation="portrait" />
        <activity android:name=".activities.ShareMessageActivity"
            android:screenOrientation="portrait"/>
        <activity
            android:name=".activities.WebViewActivity"
            android:label="@string/title_activity_web_view"
            android:theme="@style/AppTheme"/>
        <activity android:name=".activities.ContentRatingActivity"
            android:screenOrientation="portrait"/>
        <activity
            android:name="com.facebook.FacebookActivity"
            android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation"
            android:label="@string/app_name" />
        <activity
            android:name="com.facebook.CustomTabActivity"
            android:exported="true">
            <intent-filter>
                <action android:name="android.intent.action.VIEW" />

                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />

                <data android:scheme="@string/fb_login_protocol_scheme" />
            </intent-filter>
        </activity>

        <!--
        <provider
            android:name=".AssetContentProvider"
            android:authorities="${packageName}.AssetContentProvider"
            android:exported="false"
            android:multiprocess="false"/>
        <provider
            android:name="com.facebook.FacebookContentProvider"
            android:authorities="com.facebook.app.FacebookContentProvider547123654789621"
            android:exported="true" />
        <provider
            android:name="android.support.v4.content.FileProvider"
            android:authorities="${packageName}.provider"
            android:exported="false"
            android:multiprocess="true"
            android:grantUriPermissions="true">
            <meta-data
                android:name="android.support.FILE_PROVIDER_PATHS"
                android:resource="@xml/file_paths" />
        </provider> -->

        <service android:name=".services.FCMIDService">
            <intent-filter>
                <action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
            </intent-filter>
        </service>
        <service android:name=".services.FCMService">
            <intent-filter>
                <action android:name="com.google.firebase.MESSAGING_EVENT" />
            </intent-filter>
        </service>
    </application>

</manifest>

我将不胜感激任何建议或想法。 谢谢

编辑 这是一些其他信息,即ANR日志:

apply plugin: 'com.android.application'
apply plugin: 'io.fabric'

android {
   compileSdkVersion 27
   buildToolsVersion "27.0.3"

defaultConfig {
    applicationId "com.somepackagename"
    minSdkVersion 17
    targetSdkVersion 27
    renderscriptTargetApi 22
    renderscriptSupportModeEnabled true
    versionCode 34
    versionName "1.0.34"
    multiDexEnabled true
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    api fileTree(dir: 'libs', include: ['*.jar'])

    api group: 'commons-lang', name: 'commons-lang', version: '2.6'
    api 'com.android.support:multidex:1.0.1'
    api 'com.android.support:cardview-v7:27.1.1'
    api 'com.android.support:percent:27.1.1'
    api 'com.android.support.constraint:constraint-layout:1.0.2'
    api 'com.android.support:appcompat-v7:27.1.1'
    api 'com.mikhaellopez:circularimageview:3.0.2'
    api 'com.android.support:design:27.1.1'
    api 'fr.tvbarthel.blurdialogfragment:lib:2.2.0'
    api 'com.github.channguyen:rsv:1.0.1'
    api 'com.squareup.retrofit2:retrofit:2.1.0'
    api 'com.squareup.retrofit2:converter-gson:2.1.0'
    api 'net.danlew:android.joda:2.9.4.3'
    //implementation 'com.facebook.android:facebook-android-sdk:4.17.0'
    implementation 'com.facebook.android:facebook-android-sdk:[4,5)'
    api 'com.google.zxing:core:3.3.0'
    api 'com.google.android.gms:play-services-maps:11.0.2'
    api 'com.google.android.gms:play-services-ads:11.0.2'
    api 'com.google.android.gms:play-services-auth:11.0.2'
    api 'com.google.firebase:firebase-ads:11.0.2'
    api 'com.google.firebase:firebase-messaging:11.0.2'
    api 'com.google.firebase:firebase-core:11.0.2'
    api 'com.google.firebase:firebase-invites:11.0.2'
    api 'com.nvanbenschoten.motion:library:1.1.2'
    api 'com.google.ads.interactivemedia.v3:interactivemedia:3.7.2'
    api('com.crashlytics.sdk.android:crashlytics:2.7.1@aar') {
        transitive = true;
    }
    api('com.twitter.sdk.android:twitter-core:2.3.0@aar') {
        transitive = true;
    }
    api('com.twitter.sdk.android:tweet-composer:2.2.0@aar') {
        transitive = true;
    }
    api 'com.drewnoakes:metadata-extractor:2.11.0'
}

apply plugin: 'com.google.gms.google-services'

FCMIDService类:

09-04 10:10:31.360 772-791/? E/ActivityManager: ANR in com.somepackagename
PID: 18073
Reason: executing service com.somepackagename/.services.FCMIDService
Load: 8.05 / 8.37 / 8.36
CPU usage from 26127ms to 0ms ago (2018-09-04 10:10:01.774 to 2018-09-04 10:10:27.901):
  3.4% 772/system_server: 2.2% user + 1.2% kernel / faults: 658 minor
  0.5% 599/media.codec: 0.3% user + 0.1% kernel / faults: 407 minor
  0.8% 434/surfaceflinger: 0.4% user + 0.3% kernel / faults: 10 minor
  0.6% 3942/com.google.android.gms.persistent: 0.4% user + 0.1% kernel / faults: 239 minor
  0.5% 2323/com.android.phone: 0.2% user + 0.3% kernel / faults: 5 minor
  0.4% 21381/adbd: 0.1% user + 0.3% kernel / faults: 421 minor
  0.1% 593/media.extractor: 0% user + 0% kernel / faults: 86 minor
  0.4% 3899/kworker/u16:3: 0% user + 0.4% kernel
  0.4% 12837/kworker/0:2: 0% user + 0.4% kernel
  0.3% 10/rcu_preempt: 0% user + 0.3% kernel
  0.3% 1969/com.android.systemui: 0.2% user + 0.1% kernel / faults: 10 minor
  0.3% 367/logd: 0.1% user + 0.1% kernel / faults: 13 minor
  0.3% 18068/kworker/1:1: 0% user + 0.3% kernel
  0.2% 301/msm-core:sampli: 0% user + 0.2% kernel
  0.2% 16559/kworker/0:1: 0% user + 0.2% kernel
  0.2% 432/msm_irqbalance: 0% user + 0.1% kernel
  0.2% 485/irq/215-fc38800: 0% user + 0.2% kernel
  0.2% 4096/com.google.android.gms: 0.1% user + 0.1% kernel / faults: 66 minor
  0.2% 6227/com.google.android.ims: 0.1% user + 0% kernel / faults: 110 minor
  0.1% 250/cfinteractive: 0% user + 0.1% kernel
  0.1% 258/mmcqd/0: 0% user + 0.1% kernel
  0.1% 17837/com.vkontakte.android: 0.1% user + 0% kernel / faults: 6 minor
  0.1% 15/ksoftirqd/1: 0% user + 0.1% kernel
  0.1% 428/android.hardware.wifi@1.0-service: 0% user + 0.1% kernel
  0.1% 17656/kworker/u16:2: 0% user + 0.1% kernel
  0.1% 18023/com.Project100Pi.themusicplayer: 0% user + 0% kernel / faults: 34 minor
  0.1% 3/ksoftirqd/0: 0% user + 0.1% kernel
  0.1% 40/kworker/u17:0: 0% user + 0.1% kernel
  0% 57/system: 0% user + 0% kernel
  0.1% 368/servicemanager: 0% user + 0% kernel
  0.1% 575/thermal-engine: 0% user + 0.1% kernel
  0.1% 15700/mdss_fb0: 0% user + 0.1% kernel
  0% 8/rcuc/0: 0% user + 0% kernel
  0% 170/hwrng: 0% user + 0% kernel
  0% 433/lmkd: 0% user + 0% kernel
  0% 586/zygote: 0% user + 0% kernel / faults: 158 minor
  0% 7655/ru.gismeteo.gismeteo: 0% user + 0% kernel / faults: 19 minor
  0% 10682/com.android.vending: 0% user + 0% kernel / faults: 23 minor
  0% 14340/com.android.chrome:sandboxed: 0% user + 0% kernel / faults: 4 minor
  0% 17489/com.google.android.gm: 0% user + 0% kernel / faults: 39 minor
  0% 18073/com.somepackagename: 0% user + 0% kernel / faults: 10 minor
  0% 18605/kworker/u16:4: 0% user + 0% kernel
  0% 28197/kworker/3:2: 0% user + 0% kernel
  0% 5/kworker/0:0H: 0% user + 0% kernel
  0% 13/rcuc/1: 0% user + 0% kernel
  0% 20/ksoftirqd/2: 0% user + 0% kernel
  0% 25/ksoftirqd/3: 0% user + 0% kernel
  0% 44/irq/51-cpr: 0% user + 0% kernel
  0% 47/ksoftirqd/4: 0% user + 0% kernel
  0% 160/mdss_dsi_event: 0% user + 0% kernel
  0% 262/irq/224-spdm_bw: 0% user + 0% kernel
  0% 467/ksoftirqd/5: 0% user + 0% kernel
  0% 545/dmcrypt_write: 0% user + 0% kernel
  0% 564/jbd2/dm-2-8: 0% user + 0% kernel
  0% 576/qmuxd: 0% user + 0% kernel / faults: 9 minor
  0% 578/perfd: 0% user + 0% kernel / faults: 12 minor
  0% 587/audioserver: 0% user + 0% kernel / faults: 187 minor
  0% 594/media.metrics: 0% user + 0% kernel / faults: 53 minor
  0% 596/netd: 0% user + 0% kernel / faults: 63 minor
  0% 598/wificond: 0% user + 0% kernel / faults: 1 minor
  0% 600/rild: 0% user + 0% kernel
  0% 610/cnd: 0% user + 0% kernel
  0% 1835/wpa_supplicant: 0% user + 0% kernel / faults: 1 minor
  0% 3984/com.quicinc.cne.CNEService: 0% user + 0% kernel / faults: 7 minor
  0% 4118/com.google.android.googlequicksearchbox:search: 0% user + 0% kernel / faults: 15 minor
  0% 5010/com.facebook.orca: 0% user + 0% kernel / faults: 5 minor
  0% 5082/com.facebook.katana:notification: 0% user + 0% kernel / faults: 150 minor
  0% 7216/kworker/u17:6: 0% user + 0% kernel
  0% 15818/irq/504-synapti: 0% user + 0% 

根据日志public class FCMIDService extends FirebaseInstanceIdService{ private static final String TAG = "FCMIDService"; /** * Called if InstanceID token is updated. This may occur if the security of * the previous token had been compromised. Note that this is called when the InstanceID token * is initially generated so this is where you would retrieve the token. */ @Override public void onTokenRefresh() { CLog.d(TAG, "FCM id received"); // Get updated InstanceID token. String token = FirebaseInstanceId.getInstance().getToken(); //Do something with the token //... } @Override public void onCreate() { Log.d("atf", "on create here called"); super.onCreate(); } } 属于 FCMIDService 类,但这没有任何意义。当我调试应用程序时,永远不会调用ANR方法。那么如果onCreate()从未执行过,怎么会掉在那里?

另一个重要提示: 当我将代码回滚到以前的工作版本(通过SVN)时,相同的问题仍然存在,这使我认为我使用的一个库的存储库已更改。

EDIT2: 经过一些试验,我发现问题是由ANR引起的。  当我删除行

Facebook integration

及其所有与之相关的Java代码,"implementation 'com.facebook.android:facebook-android-sdk:[4,5)'" 消失了。 我无法辞职于Facebook实施,因此我更换了

ANR

"implementation 'com.facebook.android:facebook-android-sdk:[4,5)'" 

根据https://mvnrepository.com/artifact/com.facebook.android/facebook-android-sdk/3.19.0。但这没用。

有任何解决方法的想法吗?

3 个答案:

答案 0 :(得分:3)

问题出现在Facebook存储库中。 我只是更改了app.gradle文件中的一行代码: 来自

implementation 'com.facebook.android:facebook-android-sdk:[4,5)'

api 'com.facebook.android:facebook-share:4.36.0'

就是这样,没有其他更改。

这就是正在发生的事情: 由于我在依赖性声明 [4,5)中使用了版本范围,因此gradle会自动将Facebook库更新为最新版本(当前为4.36.0)。而且Facebook最近确实更新了他们的存储库,那是我开始遇到问题的时候。

解决方案是不实施其完整的sdk(com.facebook.android:facebook-android-sdk:[4,5)),而仅实施其中的一部分(com.facebook.android : facebook-share :4.36.0),由于我现在没有版本范围,因此,如果Facebook决定再次进行更新,我应该不会有任何问题。

显然,最新的Facebook库中的某些内容开始与某些内容发生冲突,或者他们只是干得很烂。

答案 1 :(得分:0)

在调用super.onCreate()之前不要放置语句;这是非法的,并且很有可能是您从背景ANR获得Service的原因,而背景UiThread几乎无法运行-并且FirebaseInstanceIdService已过时,因此应完全替换。

答案 2 :(得分:-1)

当阻塞UI线程的时间过长时,基本上会发生这种情况。因此,请检查您最近执行阻止UI线程操作的代码。有关ANR的更多信息,请访问: https://developer.android.com/topic/performance/vitals/anr