我在我的应用程序中使用本机库,该库仅为armeabi,armeabi-v7a和x86编译.
在像Samsung S6这样的64位设备上加载此库时,应用程序崩溃并出现UnsatisfiedLinkError
java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/com.myapp-2/base.apk"],nativeLibraryDirectories=[/data/app/com.myapp-2/lib/arm64, /vendor/lib64, /system/lib64]]] couldn't find "libfoo.so"
at java.lang.Runtime.loadLibrary(Runtime.java:366)
at java.lang.System.loadLibrary(System.java:989)
Run Code Online (Sandbox Code Playgroud)
不幸的是,图书馆是封闭的来源.有没有办法解决这个问题而无需使用64位目标重新编译库?
也许我在这里遗漏了一些东西,但我无法在Play Services 6.5中使用新的Maps依赖项
我得到以下异常:
java.lang.NoSuchFieldError: No static field MapAttrs of type
[I in class Lcom/google/android/gms/R$styleable; or its superclasses
(declaration of 'com.google.android.gms.R$styleable' appears in
/data/app/com.kaching.merchant.dev1-1/base.apk)
at com.google.android.gms.maps.GoogleMapOptions
.createFromAttributes(Unknown Source)
at com.google.android.gms.maps.SupportMapFragment
.onInflate(Unknown Source)
Run Code Online (Sandbox Code Playgroud)
表现:
<meta-data android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="my-awesome-key"/>
<uses-permission
android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
Run Code Online (Sandbox Code Playgroud)
Gradle文件:
compile 'com.google.android.gms:play-services-maps:6.5.+'
compile 'com.android.support:support-v4:21.0.2'
Run Code Online (Sandbox Code Playgroud)
布局:
<fragment
android:id="@+id/map"
android:name="com.google.android.gms.maps.MapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
Run Code Online (Sandbox Code Playgroud)
这是坏了还是我做错了什么?
完整的捆绑推动了我超过dex限制,我宁愿不使用multidex
android google-play-services google-maps-android-api-2 android-gradle-plugin
我使用FragmentPagerAdapter包含几个片段,需要通知有关更改database.我通过迭代片段来实现这一点,片段实现了一个回调接口,并调用了一个refreshData()方法.
这可以正常工作,直到设备改变方向.在方向更改后,即使方法调用似乎有效,片段UI也不会明显刷新.
从我到目前为止所读到的,这是因为FragmentPagerAdapter片段生命周期的句柄和接收回调的片段不是实际显示的片段.
private class DataPagerAdapter extends FragmentPagerAdapter {
private DataFragment[] fragments = new DataFragment[] {
new FooDataFragment(), BarDataFragment()};
public DataPagerAdapter(android.support.v4.app.FragmentManager fm) {
super(fm);
}
@Override
public Fragment getItem(int position) {
return fragments[position];
}
@Override
public int getCount() {
return fragments.length;
}
public DataFragment[] getFragments() {
return fragments;
}
}
protected void refreshData() {
for (DataFragment dataFragment : mPagerAdapter.getFragments()) {
dataFragment.refreshData();
}
Run Code Online (Sandbox Code Playgroud)
我在每个片段中使用广播接收器暂时解决了这个问题,但这个解决方案似乎很浪费,可能会造成内存泄漏.如何正确解决这个问题?我在横向模式下使用不同的布局和逻辑,因此我想在方向更改后使用新创建的片段.
我正在构建一个打包为aar并分发给第三方开发人员的Android库.
结构非常简单:
项目--- libraryA --- libraryB
libraryA需要libraryB,这就是为什么在它的gradle文件中有这个:
compile project(':libraryB')
Run Code Online (Sandbox Code Playgroud)
而settings.gradle有
include ':libraryB', ':libraryA'
Run Code Online (Sandbox Code Playgroud)
但是,如果我将项目构建为aar,它只包含libraryA.我错过了什么?
我阅读了对此的回答:Android Studio如何从多个库项目中打包单个AAR?
这还不可能吗?我认为将代码拆分成多个模块并不是一种不好的做法?
我正在使用Gradle构建一个Android库项目并将其作为aar部署到maven存储库.
该库有一些依赖项,应该包含在POM中
随着apply plugin: 'maven'无POM文件不存在,只是假象
随着apply plugin: 'maven-publish'生成POM文件,但它不包括任何依赖关系
有任何想法吗?这只是不支持吗?
Gradle 2.2和Android Gradle Plugin 1.1.0
第一种方法:
configurations {
archives {
extendsFrom configurations.default
}
}
afterEvaluate { project ->
uploadArchives {
configuration = configurations.archives
repositories {
mavenDeployer {
repository(url: "http://nexus-url") {
authentication(userName: nexusUsername, password: nexusPassword)
pom.groupId = 'com.example'
pom.version = '123-SNAPSHOT'
pom.artifactId = 'foo'
pom.packaging = 'aar'
pom.project {
artifactId = 'bar'
packaging 'aar'
description 'baz'
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
也尝试了它没有包装它 afterEvaluate
第二种方法:
publishing {
publications {
sdk(MavenPublication) …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用选择器为ViewPager实现一个简单的点指示器.
当页面改变时,点应该改变颜色和大小,但它们只改变颜色,而大小保持不变.
选择器:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_selected="true">
<shape android:shape="oval">
<size
android:height="12dp"
android:width="12dp"/>
<solid android:color="@color/highlight"/>
</shape>
</item>
<item>
<shape android:shape="oval">
<size
android:height="6dp"
android:width="6dp"/>
<solid android:color="@color/light_grey"/>
</shape>
</item>
</selector>
Run Code Online (Sandbox Code Playgroud)
用于布局
<ImageView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="@dimen/margin_2x"
android:src="@drawable/dot_selector">
</ImageView>
Run Code Online (Sandbox Code Playgroud)
在onCreate()中使用它来显示初始状态:
for (int i = 0; i < mPagerAdapter.getCount(); i++) {
getLayoutInflater().inflate(R.layout.dot_indicator, viewPagerCountDots);
}
viewPagerCountDots.getChildAt(0).setSelected(true);
Run Code Online (Sandbox Code Playgroud)
这看起来像预期的那样
但当我改变页面改变时的选择器状态...
@Override
public void onPageSelected(int position) {
for (int i = 0; i < mPagerAdapter.getCount(); i++) {
viewPagerCountDots.getChildAt(i).setSelected(i == position);
}
}
Run Code Online (Sandbox Code Playgroud)
.. ..看起来像这样:
使子项无效或ViewGroup不执行任何操作.有什么线索这里出了什么问题?
更新
我正在连接蓝牙LE外设作为中心.我正在将数据写入特征,并通过20个字节的块中的通知接收数据.
通知订阅:
private void setCharacteristicNotification(BluetoothGattCharacteristic characteristic, boolean enabled) {
if (mBluetoothAdapter == null || mBluetoothGatt == null) {
Log.w("BluetoothAdapter not initialized");
return;
}
Log.d("Enabling Notifications");
mBluetoothGatt.setCharacteristicNotification(characteristic, enabled);
BluetoothGattDescriptor descriptor =
characteristic.getDescriptor(UUID.fromString(CLIENT_CHARACTERISTIC_CONFIG));
descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
mBluetoothGatt.writeDescriptor(descriptor);
}
Run Code Online (Sandbox Code Playgroud)
如果在写入之间只需要接收少量块,则这可以正常工作.蓝牙堆栈为每个块发送通知:
D/BluetoothGatt? onNotify() - Device=B0:EC:8F:00:07:AA UUID=06d1e5e7-79ad-4a71-8faa-373789f7d93c
Run Code Online (Sandbox Code Playgroud)
但是如果写入之间的块数大于10,则堆栈会停止通知,其余数据将丢失!该设备肯定会发送更多数据,因为我们可以在iOS设备上接收它.
收到的通知数量因Android设备而异.Galaxy S3(4.3)接收5,nexus 5(4.4.4)和htc one(4.4.2)接收12.
BT堆栈在最后一次通知后30秒关闭连接.
D/BluetoothGatt? onClientConnectionState() - status=0 clientIf=5 device=B0:EC:8F:00:00:88
Run Code Online (Sandbox Code Playgroud)
任何人都能重现这个问题吗?
由于蓝牙LE堆栈是基于轮询的,我想堆栈由于某种原因停止从外围设备轮询数据.目标设备不支持指示.
更新:Android L蓝牙堆栈提供的其他信息:
06-27 12:20:02.982 18909-18946/? D/BtGatt.GattService? onNotify() - address=B0:EC:8F:00:01:09, charUuid=06d1e5e7-79ad-4a71-8faa-373789f7d93c, length=20
Run Code Online (Sandbox Code Playgroud)
06-27 12:20:07.666 18909-18984 /?E/BTLD:############################################### ######################## 06-27 12:20:07.666 18909-18984 /?E/BTLD:#06-27 12:20:07.666 18909-18984 /?E/BTLD:#警告:BTU HCI(id = 0)命令超时.操作码= …
我已成功使用此代码在应用程序和Robolectric 2.4的单元测试中加载资源:
getContext().getResources().getIdentifier(resName, "string", getContext().getPackageName());
Run Code Online (Sandbox Code Playgroud)
其中Context是App中的MyApplication和Robolectric测试中的TestMyApplication.
使用Robolectric 3.0,当将applicationIdSuffix添加到构建文件时,该调用将不再有效,该调用返回0.
这是一个已知的问题?这是在com.android.tools.build:gradle:1.2.0-beta1和org.robolectric:robolectric:3.0-rc2
我首先给布局充气,然后使用addView()向它添加一个View.该布局附加了一个OnLongClickListener.
如果我现在向内部视图添加OnClickListener,OnLongClickListener不再触发.我怎样才能解决这个问题?
示例代码:
View someLayout = getLayoutInflater().inflate(R.layout.some_layout, null);
someLayout.setOnLongClickListener(new OnLongClickListener() {
@Override
public boolean onLongClick(View arg0) {
...
return true;
}
});
TextView innerView = new TextView(this);
innerView.setText("JustSomeTextThatDoesNotMatter");
innerView.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
...
);
}
});
((FrameLayout) view.findViewById(R.id.framelayout)).addView(innerView);
Run Code Online (Sandbox Code Playgroud)
布局
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center" >
<FrameLayout
android:id="@+id/framelayout"
android:layout_width="300dp"
android:layout_height="wrap_content">
</FrameLayout>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?这看起来真的很奇怪.
更新:当我使用onTouchListener而不是onLongClickListener时会发生同样的事情,内部视图中的OnClickListener会消耗所有触摸事件.
这是设计的吗?我想要的基本上是ContextMenu为ListView提供的功能.
android ×9
gradle ×2
android-ndk ×1
bluetooth ×1
layout ×1
maven ×1
ndk-build ×1
robolectric ×1
unit-testing ×1