0

I was trying this example code to view maps offline in Android Studio. First I got the error "Cannot resolve symbol 'osmdroid'". I imported an external library which solved the error but then i got the errors "Cannot resolve symbol 'GeoPoint'" and "Cannot resolve symbol 'MapView'". Is there another external library for this or can i use this code with some changes?

package com.example.hppavilion15.osmoffline1;

import org.osmdroid.util.GeoPoint;
import org.osmdroid.views.MapView;
import android.app.Activity;
import android.os.Bundle;

public class OSMDroidMapActivity extends Activity {

public void onCreate(Bundle savedInstanceState){

    super.onCreate(savedInstanceState);

    MapView mapView = new MapView(this, 256); //constructor

    mapView.setClickable(true);

    mapView.setBuiltInZoomControls(true);

    setContentView(mapView); //displaying the MapView

    mapView.getController().setZoom(15); //set initial zoom-level, depends on your need

    mapView.getController().setCenter(new GeoPoint(52.221, 6.893)); //This point is in Enschede, Netherlands. You should select a point in your map or get it from user's location.

    mapView.setUseDataConnection(false); //keeps the mapView from loading online tiles using network connection.

    }

}

my build.gradle file:

buildscript {
repositories {
    jcenter()
}
dependencies {
    classpath 'com.android.tools.build:gradle:1.3.0'

    // NOTE: Do not place your application dependencies here; they belong
    // in the individual module build.gradle files
   }
}

allprojects {
   repositories {
      jcenter()
   }
}

other gradle file:

apply plugin: 'com.android.application'

android {
compileSdkVersion 23
buildToolsVersion "23.0.0"

defaultConfig {
    applicationId "com.example.hppavilion15.osmoffline1"
    minSdkVersion 15
    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'])
compile 'com.android.support:appcompat-v7:23.0.0'
}

main\AndroidManifest.xml:

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

<application android:allowBackup="true" android:label="@string/app_name"
    android:icon="@mipmap/ic_launcher" android:theme="@style/AppTheme">
    <activity
        android:name="com.example.hppavilion15.osmoffline1.OSMDroidMapActivity"
        android:nohistory="false" android:theme="@android:style/Theme.NoTitleBar"
        android:launchmode="singleTask" android:hardwareaccelerated="false"
        android:configchanges="keyboardHidden|orientation">
    </activity>
</application>

debug\AndroidManifest.xml:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.hppavilion15.osmoffline1"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
    android:minSdkVersion="15"
    android:targetSdkVersion="23" />

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name="com.example.hppavilion15.osmoffline1.OSMDroidMapActivity"
        android:configchanges="keyboardHidden|orientation"
        android:hardwareaccelerated="false"
        android:launchmode="singleTask"
        android:nohistory="false"
        android:theme="@android:style/Theme.NoTitleBar" >
    </activity>
</application>

Gradle build messages:

Error:(16) No resource identifier found for attribute 'configchanges' in package 'android'

Error:(16) No resource identifier found for attribute 'hardwareaccelerated' in package 'android'

Error:(16) No resource identifier found for attribute 'hardwareaccelerated' in package 'android'

Error:(16) No resource identifier found for attribute 'launchmode' in package 'android' Error:(16) No resource identifier found for attribute 'nohistory' in package 'android'

Error:Execution failed for task ':app:processDebugResources'. com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Users\HP PAVILION 15\AppData\Local\Android\sdk\build-tools\23.0.0\aapt.exe'' finished with non-zero exit value 1 Information:BUILD FAILED Information:Total time: 1.754 secs Information:5 errors Information:0 warnings Information:See complete output in console

Community
  • 1
  • 1
petebp
  • 33
  • 1
  • 5
  • Do you use gradle? How does your gradle file look? – m02ph3u5 Aug 23 '15 at 17:52
  • @m02ph3u5 my build.gradle file buildscript { repositories { jcenter() } dependencies { classpath 'com.android.tools.build:gradle:1.3.0' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files } } allprojects { repositories { jcenter() } } – petebp Aug 23 '15 at 19:01
  • You posted the wrong gradle script, do you have another? – spy Aug 23 '15 at 21:52
  • @spy thanks, i just posted it – petebp Aug 23 '15 at 23:03
  • You have to add google play services lib to your app gradle dependencies – Max Pinto Aug 23 '15 at 23:34
  • @Max Pinto I have just changed the dependencies but it didn't work – petebp Aug 23 '15 at 23:52
  • Ok, after add the google play services lib sync your project. Then clean and rebuild. If that doesnt work try to invalidate caché / restart android estudio, if that doesnt work, show the logcat detailed. Regards – Max Pinto Aug 24 '15 at 00:49
  • @Max Pinto thanks, i've just tried them but didn't work out i can't open the Android Device Monitor. It says "An error has occured.". – petebp Aug 24 '15 at 01:25

1 Answers1

0

Since you're using osmdroid, you'll need to add osmdroid as a dependency to the application module gradle file (the second one). See the readme at https://github.com/osmdroid/osmdroid/wiki/HowToMaven for more info

dependencies {
 compile fileTree(dir: 'libs', include: ['*.jar'])
 compile 'com.android.support:appcompat-v7:23.0.0'
 compile 'org.osmdroid:osmdroid-android:4.3'
}

that should get you going.

edit: here's an example manifest. source Try adding these to your manifest.

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

<uses-feature android:name="android.hardware.location.network" android:required="false" />
<uses-feature android:name="android.hardware.location.gps" android:required="false" />
<uses-feature android:name="android.hardware.telephony" android:required="false" />
<uses-feature android:name="android.hardware.wifi" android:required="false" />
spy
  • 3,199
  • 1
  • 18
  • 26
  • thanks man it really helped me, but now the app doesn't run can, i guess the problem seems to be the manifest file. Can you please check it? I've just posted it. – petebp Aug 24 '15 at 08:10
  • thanks but it didn't wor either. I've also added gradle build messages – petebp Aug 24 '15 at 11:55