添加Google Play服务依赖项会导致运行时错误

时间:2018-07-04 21:42:45

标签: java android aide-ide aide

自从上次对AIDE更新以来,我一直在使用Google Play服务时遇到问题。我发现,仅将依赖关系添加到我的构建gradle文件中将导致发生运行时错误,并且没有它我的应用程序将正常运行。我只是想在pageviewer中使用google map,但是我不能仅仅添加依赖项。

这是我的build.gradle:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 21
    buildToolsVersion "21.1.0"

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

dependencies {
    //compile 'com.google.android.gms:play-services-maps:+'
  compile fileTree(dir: 'libs', include: ['*.jar'])
}

在未注释掉依赖项的情况下,出现以下运行时错误: java.lang.RuntimeException:无法实例化活动ComponentInfo {com.Smartz.CoPilot / com.Smartz.CoPilot.PageViewActivity}:java.lang.ClassNotFoundException:在路径中找不到类“ com.Smartz.CoPilot.PageViewActivity”。 DexPathList [[zip文件“ /data/app/com.Smartz.CoPilot-1/base.apk"],nativeLibraryDirectories=[/data/app/com.Smartz.CoPilot-1/lib/arm、/vendor/lib, / system / lib]]

这是我的清单:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.Smartz.CoPilot" >

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme"
            android:resizeableActivity = "true">
        <activity
            android:name=".PageViewActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

这是我的活动代码:

package com.Smartz.CoPilot;

import java.util.ArrayList;
import java.util.List;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;

public class PageViewActivity extends FragmentActivity {
    MyPageAdapter pageAdapter;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_page_view);

        List<Fragment> fragments = getFragments();

        pageAdapter = new MyPageAdapter(getSupportFragmentManager(), fragments);

        ViewPager pager = findViewById(R.id.viewpager);
        pager.setAdapter(pageAdapter);

    }

    private List<Fragment> getFragments(){
        List<Fragment> fList = new ArrayList<Fragment>();

        fList.add(RedFragment.newInstance("Red Fragment"));
        //fList.add(MyFragment.newInstance("Fragment 2"));
        //fList.add(MyFragment.newInstance("Fragment 3"));

        return fList;
    }

    private class MyPageAdapter extends FragmentPagerAdapter {
        private List<Fragment> fragments;

        public MyPageAdapter(FragmentManager fm, List<Fragment> fragments) {
            super(fm);
            this.fragments = fragments;
        }
        @Override
        public Fragment getItem(int position) {
            return this.fragments.get(position);
        }

        @Override
        public int getCount() {
            return this.fragments.size();
        }
    }
}

这是我的片段代码:

package com.Smartz.CoPilot;

    import android.os.Bundle;
    import android.support.v4.app.Fragment;
    import android.view.LayoutInflater;
    import android.view.View;
    import android.view.ViewGroup;
    import android.widget.TextView;
import android.graphics.*;
import android.view.View.*;

public class RedFragment extends Fragment implements OnClickListener {

    @Override
    public void onClick(View p1) {
        // TODO: Implement this method
    }

        public static final String EXTRA_MESSAGE = "EXTRA_MESSAGE";

        public static final MyFragment newInstance(String message)
        {
            MyFragment f = new MyFragment();
            Bundle bdl = new Bundle(1);
        bdl.putString(EXTRA_MESSAGE, message);
        f.setArguments(bdl);
        return f;
        }

        @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, 
                                                         Bundle savedInstanceState) {
            String message = getArguments().getString(EXTRA_MESSAGE);
            View v = inflater.inflate(R.layout.myfragment_layout, container, false);
            TextView messageTextView = (TextView)v.findViewById(R.id.textView);
            messageTextView.setText(message);


            return v;
    }



    }

我有一个完整的应用程序,使用了viewpager中的supportMapFragment可以使用一年,自从最新的AIDE更新以来,我无法进行编译。

感谢您提供的任何帮助。

0 个答案:

没有答案