就像我在测试一个nexus s(4.0.4提供google play服务)和avd(4.2.2 with google api)之前遇到的问题一样,在这两种情况下,locationclient getLastLocation()
总是返回null
.
public class MainActivity extends Activity implements LocationListener,
GooglePlayServicesClient.ConnectionCallbacks,
GooglePlayServicesClient.OnConnectionFailedListener {
private LocationClient mLocationClient;
private LocationRequest mLocationRequest;
boolean mUpdatesRequested = false;
boolean mConnected = false;
SharedPreferences mPrefs;
SharedPreferences.Editor mEditor;
private TextView mText;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mText = (TextView) findViewById(R.id.text);
mLocationRequest = LocationRequest.create();
mLocationRequest
.setInterval(LocationUtils.UPDATE_INTERVAL_IN_MILLISECONDS);
mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
mLocationRequest
.setFastestInterval(LocationUtils.FAST_INTERVAL_CEILING_IN_MILLISECONDS);
mUpdatesRequested = false;
mPrefs = getSharedPreferences(LocationUtils.SHARED_PREFERENCES,
Context.MODE_PRIVATE);
mEditor = mPrefs.edit();
mLocationClient = new LocationClient(this, this, this);
}
@Override
public …
Run Code Online (Sandbox Code Playgroud) 我们有两个名为app和lib的模块.由于我们必须将rn添加到lib中,因此我们添加了lib的build.gradle:
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile "com.facebook.react:react-native:+" // From node_modules}
Run Code Online (Sandbox Code Playgroud)
并在项目的build.gradle中
allprojects {
repositories {
mavenLocal()
jcenter()
maven {
// All of React Native (JS, Android binaries) is installed from npm
url "$rootDir/../node_modules/react-native/android"
}
}}
Run Code Online (Sandbox Code Playgroud)
和node_modules已经下载并放在通常的文件夹中,包含package.json
"dependencies": {
"react": "15.1.0",
"react-native": "0.28.0" }
Run Code Online (Sandbox Code Playgroud)
和
G:\dev>react-native -v
react-native-cli: 1.0.0
react-native: 0.28.0
我们的活动有
<orderEntry type="library" exported="" name="react-native-0.28.0" level="project" />
Run Code Online (Sandbox Code Playgroud)
在lib.iml
,能及时发现反应原生0.28的依赖一样okhttp-3.2.0
,并okio-1.8.0
在工作室的外部库(从来没有使用过或前加入),
但react-native-0.28.0
从未出现在工作室的外部库中,并且对代码无效.
任何想法为什么会发生?提前致谢.
更新
在我compile 'com.android.support:appcompat-v7:23.1.1'
输入app模块之后react-native-0.28.0
出现了依赖...这很奇怪,这是一个bug还是什么?