Android.support.multidex.MultiDexApplication нельзя преобразовать в имя приложения

Я столкнулся с ошибкой после добавления multidex: android:name = "android.support.multidex.MultiDexApplication" в манифест, и вот мой файл build.gradle:

apply plugin: 'com.android.application'

android {
compileSdkVersion 26
buildToolsVersion '26.0.2'

defaultConfig {
    applicationId "com.projects.realestatefinder"
    minSdkVersion 15
    targetSdkVersion 26
    versionCode 1
    versionName "1.0"
    multiDexEnabled true
    vectorDrawables.useSupportLibrary = true
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        resValue "string", "google_maps_api_key", "AIzaSyBugjavAKmDVOmR0HMhD83Cyru5V0GsCro"
    }
    debug {
        resValue "string", "google_maps_api_key", "AIzaSyBugjavAKmDVOmR0HMhD83Cyru5V0GsCro"
    }
}

packagingOptions {
    exclude 'META-INF/DEPENDENCIES'
    exclude 'META-INF/NOTICE'
    exclude 'META-INF/LICENSE'
    exclude 'META-INF/LICENSE.txt'
    exclude 'META-INF/NOTICE.txt'
}
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:26.0.2'
compile 'com.android.support:design:26.0.2'
compile 'com.android.support:multidex:1.0.0'
compile files('libs/apache-mime4j-0.6.jar')
compile files('libs/httpclient-4.3.4.jar')
compile files('libs/httpcore-4.3.2.jar')
compile files('libs/httpmime-4.3.4.jar')
compile files('libs/jackson-annotations-2.2.2.jar')
compile files('libs/jackson-core-2.2.2.jar')
compile files('libs/jackson-databind-2.2.2.jar')
compile files('libs/twitter4j-async-4.0.2.jar')
compile files('libs/twitter4j-core-4.0.2.jar')
compile files('libs/twitter4j-media-support-4.0.2.jar')
compile files('libs/twitter4j-stream-4.0.2.jar')
compile files('libs/universal-image-loader-1.9.2-SNAPSHOT-with-sources.jar')
compile 'com.google.android.gms:play-services-maps:8.4.0'
compile 'com.google.android.gms:play-services-location:8.4.0'
compile 'com.google.android.gms:play-services-ads:8.4.0'
compile 'com.facebook.android:facebook-android-sdk:4.+'
compile 'com.jakewharton:butterknife:8.2.1'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.2.1'
compile 'com.davemorrissey.labs:subsampling-scale-image-view:3.5.0'
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.melnykov:floatingactionbutton:1.3.0'
compile 'com.crystal:crystalrangeseekbar:1.1.3'
compile 'com.anthonycr.grant:permissions:1.0'
  }

класс multidex

public class YouApplication extends MultiDexApplication {
@Override
protected void attachBaseContext(Context base) {
    super.attachBaseContext(base);
    MultiDex.install(this);
}

}

Mainfest

xmlns:android = "http://schemas.android.com/apk/res/android"
package = "com.projects.realestatefinder">

<uses-permission android:name = "android.permission.INTERNET" />
<uses-permission android:name = "android.permission.CALL_PHONE" />
<uses-permission android:name = "android.permission.CAMERA" />
<uses-permission android:name = "android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name = "android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name = "android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name = "android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name = "android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name = "android.permission.SEND_SMS" />

<uses-feature android:name = "android.hardware.camera" />
<uses-feature android:name = "android.hardware.telephony" android:required = "false" />

<application
    android:name = "com.projects.realestatefinder.YouApplication"
    android:largeHeap = "true"
    android:allowBackup = "true"
    android:icon = "@mipmap/ic_launcher"
    android:label = "@string/app_name"
    android:supportsRtl = "true"
    android:theme = "@style/AppTheme">
    <activity
        android:name = ".SplashActivity"
        android:theme = "@style/SplashTheme"
        android:label = "@string/app_name">
        <intent-filter>
            <action android:name = "android.intent.action.MAIN" />
            <category android:name = "android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

    <activity
        android:name = "com.projects.activities.BuiltInActivity"
        android:theme = "@style/AppTheme"
        android:configChanges = "keyboard|keyboardHidden|orientation|screenSize"
        android:label = "@string/built_in"/>

    <activity
        android:name = "com.projects.activities.SettingsActivity"
        android:theme = "@style/AppTheme.SettingsTheme"
        android:configChanges = "keyboard|keyboardHidden|orientation|screenSize"
        android:label = "@string/settings"/>

    <activity
        android:name = "com.projects.activities.ImageViewerActivity"
        android:theme = "@style/AppTheme"
        android:label = "@string/view_image"/>

    <activity
        android:name = "com.projects.activities.AgentListingActivity"
        android:theme = "@style/AppTheme"
        android:label = "@string/agents"/>

    <activity
        android:name = "com.projects.activities.ProfileActivity"
        android:theme = "@style/AppTheme"
        android:configChanges = "keyboard|keyboardHidden|orientation|screenSize"
        android:label = "@string/profile"/>

    <activity
        android:name = "com.projects.activities.PropertyResultActivity"
        android:theme = "@style/AppTheme"
        android:label = "@string/results"/>

    <activity
        android:name = "com.projects.activities.SearchResultActivity"
        android:theme = "@style/AppTheme"
        android:label = "@string/search_results"/>

    <activity
        android:name = "com.projects.activities.RegisterAgentActivity"
        android:theme = "@style/AppTheme"
        android:label = "@string/register_agent"/>

    <activity
        android:name = "com.projects.activities.RegisterActivity"
        android:theme = "@style/AppTheme"
        android:configChanges = "keyboard|keyboardHidden|orientation|screenSize"
        android:label = "@string/register"/>

    <activity
        android:name = "com.projects.activities.RealEstateEditActivity"
        android:theme = "@style/AppTheme"
        android:configChanges = "keyboard|keyboardHidden|orientation|screenSize"
        android:label = "@string/edit_real_estate"/>

    <activity
        android:name = "com.projects.activities.RealEstateAddActivity"
        android:theme = "@style/AppTheme"
        android:configChanges = "keyboard|keyboardHidden|orientation|screenSize"
        android:label = "@string/add_real_estate"/>

    <activity
        android:name = "com.projects.activities.PropertyTypeActivity"
        android:theme = "@style/AppTheme"
        android:label = "@string/property_type"/>

    <activity
        android:name = "com.projects.activities.MyRealEstateActivity"
        android:theme = "@style/AppTheme"
        android:label = "@string/my_real_estates"/>

    <activity
        android:name = "com.projects.activities.MapActivity"
        android:theme = "@style/AppTheme"
        android:label = "@string/map"/>

    <activity
        android:name = "com.projects.activities.SearchActivity"
        android:theme = "@style/AppTheme"
        android:configChanges = "keyboard|keyboardHidden|orientation|screenSize"
        android:label = "@string/search"/>

    <activity
        android:name = "com.projects.activities.AgentDetailActivity"
        android:theme = "@style/AppTheme"
        android:label = "@string/agent_details"/>

    <activity
        android:name = "com.projects.activities.DetailActivity"
        android:theme = "@style/AppTheme"
        android:label = "@string/real_estate_details"/>

    <activity
        android:name = "com.projects.activities.LoginActivity"
        android:theme = "@style/AppTheme"
        android:configChanges = "keyboard|keyboardHidden|orientation|screenSize"
        android:label = "@string/login"/>

    <activity
        android:name = "com.projects.realestatefinder.MainActivity"
        android:theme = "@style/MainTheme"
        android:label = "@string/app_name"/>

    <!--
         The API key for Google Maps-based APIs is defined as a string resource.
         (See the file "res/values/google_maps_api.xml").
         Note that the API key is linked to the encryption key used to sign the APK.
         You need a different API key for each encryption key, including the release key that is used to
         sign the APK for publishing.
         You can define the keys for the debug and release targets in src/debug/ and src/release/.
    -->
    <meta-data
        android:name = "com.google.android.geo.API_KEY"
    android:value = "@string/google_maps_api_key" />

    <meta-data android:name = "com.facebook.sdk.ApplicationId" android:value = "@string/facebook_app_id"/>

</application>

Когда я пытаюсь запустить приложение на android 4.4, оно вылетает. Когда я открываю локацию GPS, я много ищу и не знаю, в чем проблема. Пожалуйста, дайте мне знать, что делать, чтобы решить эту проблему.

Журналы сбоев выглядят следующим образом.

java.lang.ClassCastException: android.support.multidex.MultiDexApplication cannot be cast to com.application.RealEstateApplication
                  at com.projects.fragments.MapFragment.refetch(MapFragment.java:207)
                  at com.projects.fragments.MapFragment.onMapReady(MapFragment.java:200)
                  at com.google.android.gms.maps.SupportMapFragment$zza$1.zza(Unknown Source)
                  at com.google.android.gms.maps.internal.zzo$zza.onTransact(Unknown Source)
                  at android.os.Binder.transact(Binder.java:361)
                  at fs.b(:com.google.android.gms.dynamite_dynamitemodulesb@[email protected] (000306-197041431):20)
                  at com.google.android.gms.maps.internal.bg.a(:com.google.android.gms.dynamite_dynamitemodulesb@[email protected] (000306-197041431):5)
                  at com.google.maps.api.android.lib6.impl.be.run(:com.google.android.gms.dynamite_dynamitemodulesb@[email protected] (000306-197041431):5)
                  at android.os.Handler.handleCallback(Handler.java:733)
                  at android.os.Handler.dispatchMessage(Handler.java:95)
                  at android.os.Looper.loop(Looper.java:136)
                  at android.app.ActivityThread.main(ActivityThread.java:5476)
                  at java.lang.reflect.Method.invokeNative(Native Method)
                  at java.lang.reflect.Method.invoke(Method.java:515)
                  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)
                  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
                  at dalvik.system.NativeStart.main(Native Method)
0
0
2 892
2

Ответы 2

Расширьте свой com.application.RealEstateApplication

android.app.Application

и в вашем манифесте выполните:

android:name = "com.application.RealEstateApplication"

А потом MultiDex.install(this); в onCreate()

что вы имеете в виду под расширением в mainfest или в классе, потому что я не могу добавить обе строки, одна из них должна быть в mainfest com.application.RealEstateApplication extension android.support.multidex.MultiDexApplication

waleed 10.07.2018 23:00

@waleed, если вы хотите создать подкласс класса MultiDexApplication, вы должны указать это имя класса в манифесте.

Nongthonbam Tonthoi 10.07.2018 23:07

Я добавил android:name".YouApplication" и новый класс public class YouApplication extends Application { @Override protected void attachBaseContext(Context base) { super.attachBaseContext(base); MultiDex.install(this); } } // но он не работает

waleed 10.07.2018 23:11

а также пытаюсь расширить MultiDexApplication, но ничего не работает

waleed 10.07.2018 23:17
And then MultiDex.install(this); in onCreate() в MainActivity или в классе YouApplication, который расширяет multidexapplication
waleed 10.07.2018 23:37

Вы должны расширить свой класс Application из MultidexApplication и использовать его в манифесте вместо прямого использования android.support.multidex.MultiDexApplication

public class MyApplication extends MultiDexApplication
 {
 ...
 }

И замените в своем манифесте:

android:name = "com.projects.realestatefinder.MyApplication"

Класс вашего приложения расширяет MultiDexApplication, поэтому ему не нужно (не нужно) вызывать MultiDex.install (это)

Belbahar Raouf 11.07.2018 13:31

Я не могу воспроизвести вашу ошибку, можете ли вы также добавить свой MapFragment? Спасибо.

Belbahar Raouf 11.07.2018 13:37

[stackoverflow.com/questions/51285125/… Я не могу добавить более 30 КБ символов, поэтому это фрагмент карты по ссылке

waleed 11.07.2018 14:09

этот проект без ошибок отлично работает у моего друга на компьютере, он использует android 5.0 через usb и iam, используя 4.4, это все другое

waleed 11.07.2018 14:16

Как сказано в другом потоке: попробуйте отключить мгновенный запуск: • Отключите мгновенный запуск • Очистите и перестройте проект • Удалите приложение с устройства и установите его снова без мгновенного запуска

Belbahar Raouf 11.07.2018 16:16

теперь приложение работает в эмуляторе 7.0, но gps эмулятора не работает в приложении, поэтому я пытаюсь запустить приложение на своем телефоне Android 4.4

waleed 11.07.2018 17:06

Вы разрешили своему приложению использовать GPS на эмуляторе?

Belbahar Raouf 11.07.2018 17:30

да, но GPS такой медленный, и он определяет мое местоположение amireca и iam на Ближнем Востоке

waleed 11.07.2018 17:36

С помощью эмулятора вы можете моделировать координаты.

Belbahar Raouf 11.07.2018 18:12

Другие вопросы по теме