小编stk*_*ent的帖子

protobuf lite 和 protobuf java 中的重复类

我在android实现中使用带有protobuf lite的grpc。但是 protobuf lite 没有 google 时间戳,而我的 protos 导入了“google/protobuf/timestamp.proto”。所以我添加了实现 'com.google.protobuf:protobuf-java:3.7.1' 到包含谷歌时间戳的gradle。但在那之后代码编译有错误。例如 :Duplicate class com.google.protobuf.AbstractMessageLite 在模块 protobuf-java-3.7.1.jar (com.google.protobuf:protobuf-java:3.7.1) 和 protobuf-lite-3.0.1.jar ( com.google.protobuf:protobuf-lite:3.0.1)。任何解决此问题的想法将不胜感激。

apply plugin: 'com.android.application'
apply plugin: 'com.google.protobuf'

android {
    compileSdkVersion 28
    buildToolsVersion "29.0.0"
    defaultConfig {
        minSdkVersion 21
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        debug {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }

    sourceSets {
        main {
            proto {
                srcDir 'src/main'
            }
            java {
                srcDir 'src/main'
            }
        } …
Run Code Online (Sandbox Code Playgroud)

android timestamp protocol-buffers grpc

15
推荐指数
2
解决办法
9610
查看次数

Android支持库Build v26.XX构建错误:已定义属性"font"

我正在尝试从支持库的25.3.1版本升级到版本26.X.X,但每次使用较新版本构建项目时都会出现此错误:

Error:(357) Attribute "font" already defined with incompatible format.
Error:(343) Original attribute defined here.

Error:java.util.concurrent.ExecutionException: 
com.android.ide.common.process.ProcessException: Error while executing 
process /Users/johnsmith/Library/Android/sdk/build-tools/26.0.1/aapt 
with arguments {package -f --no-crunch -I ...
Run Code Online (Sandbox Code Playgroud)

我尝试过清洁和重建.我也试过使缓存失效并重新启动Android Studio.

该应用程序可以使用25.3.1支持库的版本构建.我正在使用Android Studio 3.0 Beta 2和3.0.0-beta2Android Gradle插件版本.

android gradle android-studio

14
推荐指数
2
解决办法
4337
查看次数

为什么setCharacteristicNotification()实际上没有启用通知?

所述BluetoothLeGatt的Android BLE例如包含以下代码:

public void setCharacteristicNotification(BluetoothGattCharacteristic characteristic,
                                          boolean enabled) {
    if (mBluetoothAdapter == null || mBluetoothGatt == null) {
        Log.w(TAG, "BluetoothAdapter not initialized");
        return;
    }
    mBluetoothGatt.setCharacteristicNotification(characteristic, enabled);

    // This is specific to Heart Rate Measurement.
    if (UUID_HEART_RATE_MEASUREMENT.equals(characteristic.getUuid())) {
        BluetoothGattDescriptor descriptor = characteristic.getDescriptor(
                UUID.fromString(SampleGattAttributes.CLIENT_CHARACTERISTIC_CONFIG));
        descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
        mBluetoothGatt.writeDescriptor(descriptor);
    }
}
Run Code Online (Sandbox Code Playgroud)

我的问题基本上是,为什么标记的代码特定于心率测量?似乎具有客户端特征配置描述符(CCCD)特性是控制特征通知的标准方法,那么为什么不注意setCharacteristicNotification()写入呢?既然它不这样做,setCharacteristicNotification()实际上做了什么?

我对BLE很新,在互联网上没有任何解释,并不认为你已经理解了这一切!所以不要以为我知道什么是CCCD或其他什么!很难找到CCCD甚至代表什么!

编辑:另请参阅此答案,该答案支持我对CCCD的理解(并且让我继续想知道为什么你必须在Android中手动写入它们,当有一个看起来应该为你这样做的功能时):https:// devzone .nordicsemi.com/index.php文件/什么-做- CCCD均值

android bluetooth bluetooth-lowenergy gatt

13
推荐指数
3
解决办法
1万
查看次数

如何使用Swift打印Data类型变量的内容?

我要做的就是取一个字符串并获取其十六进制值.我一直关注这篇文章.这是我在操场上的代码:

let str = "Say Hello to My Little Friend"
let data = str.data(using: String.Encoding.utf16)
print("\(data!)")
Run Code Online (Sandbox Code Playgroud)

但是,我的代码只打印:

"60字节\n"

如何打印十六进制值?供参考,它应该是:

5361792048656c6c6f20746f204d79204c6974746c6520467269656e64
Run Code Online (Sandbox Code Playgroud)

ios swift

13
推荐指数
2
解决办法
1万
查看次数

如何正确使用setOnLongClickListener()与Kotlin

我一直在尝试设置长时间点击监听器事件,但不断收到以下错误:

Type mismatch. 

Required:Boolean

Found:Unit
Run Code Online (Sandbox Code Playgroud)

我对这个setOnClickListener 事件没有任何问题,但由于某种原因,我对这个setOnLongClickListener事件没有运气.

我目前正在尝试显示一个简单的Toast:

view.setOnLongClickListener{
    Toast.makeText(this, "Long click detected", Toast.LENGTH_SHORT).show();
}
Run Code Online (Sandbox Code Playgroud)

我见过很多关于Java的例子,但我还没有找到Kotlin的任何例子.

android onlongclicklistener kotlin

13
推荐指数
2
解决办法
8996
查看次数

构造函数/案例/警卫/ if-then-else的顺序对性能有影响吗?

我在Containers/Data/Set/Base.hs中看到了这条评论

-- [Note: Order of constructors]
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-- The order of constructors of Set matters when considering performance.
-- Currently in GHC 7.0, when type has 2 constructors, a forward conditional
-- jump is made when successfully matching second constructor. Successful match
-- of first constructor results in the forward jump not taken.
-- On GHC 7.0, reordering constructors from Tip | Bin to Bin | Tip
-- improves the benchmark by up to 10% on x86.
Run Code Online (Sandbox Code Playgroud)

订单还有哪些地方对业绩产生微小的可衡量影响?特别是我想知道有很多选项的案例陈述.

optimization haskell ghc

12
推荐指数
1
解决办法
346
查看次数

同步属性getter/setters

所以我试图了解Kotlin如何处理属性的同步.如果我有这个课程:

class Foo {
    var a = 0
    var b = 0
}
Run Code Online (Sandbox Code Playgroud)

我想确保a&b的所有访问权限都已同步.我该怎么办?我试过使用注释:

class Foo {
    @Synchronized
    var a = 0
    @Synchronized
    var b = 0
}
Run Code Online (Sandbox Code Playgroud)

但Kotlin给了我一个编译器错误:

class Foo {
    var a = 0
    var b = 0
}
Run Code Online (Sandbox Code Playgroud)

我只是想在Kotlin中更好地处理线程安全问题.这是我在Java中一直都是OCD的东西,而我正试图弄清楚如何在Kotlin中正确处理它.

java kotlin

12
推荐指数
2
解决办法
2889
查看次数

iOS 11中的UIRefreshControl()Glitchy效果

每当我拉动刷新TableView时,UIRefreshControl似乎都是毛病.以下是我正在使用的代码.有任何想法吗?

在AppDelegate中:

UINavigationBar.appearance().isTranslucent = false
UINavigationBar.appearance().barTintColor = UIColor.red
UINavigationBar.appearance().tintColor = UIColor.white
Run Code Online (Sandbox Code Playgroud)

在UITableViewController中:

self.tableView.refreshControl = UIRefreshControl()

if #available(iOS 11.0, *) {
  self.navigationController?.navigationBar.prefersLargeTitles = false
} else {
  // Fallback on earlier versions
}

self.tableView.refreshControl = refreshCont
Run Code Online (Sandbox Code Playgroud)

uirefreshcontrol swift ios11 xcode9

11
推荐指数
1
解决办法
3123
查看次数

在初始化谷歌地图时,mapFragment.getMapAsync(this)处的空指针异常

当我使用Google Play Services的v6.5.87时,我在调用时会收到空指针异常getMapAsync().我SupportMapFragment在我Fragment的xml布局中使用了一个.

我的代码:

SupportMapFragment mapFragment = (SupportMapFragment) getActivity()
        .getSupportFragmentManager().findFragmentById(R.id.mapFragment);

mapFragment.getMapAsync(this);
Run Code Online (Sandbox Code Playgroud)

注意:调用getMap()较旧的Google Play Services版本时没有问题,但getMap()现已弃用(docs).

这是NPE的堆栈跟踪:

java.lang.NullPointerException
            at com.decos.fixi.fragments.FragmentLocationMap.initializeMap(FragmentLocationMap.java:132)
            at com.decos.fixi.fragments.FragmentLocationMap.onCreateView(FragmentLocationMap.java:95)
            at android.support.v4.app.Fragment.performCreateView(Fragment.java:1786)
            at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:947)
            at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1126)
            at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:739)
            at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1489)
            at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:454)
            at android.os.Handler.handleCallback(Handler.java:615)
            at android.os.Handler.dispatchMessage(Handler.java:92)
            at android.os.Looper.loop(Looper.java:137)
            at android.app.ActivityThread.main(ActivityThread.java:4921)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:511)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1027)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:794)
            at dalvik.system.NativeStart.main(Native Method)
Run Code Online (Sandbox Code Playgroud)

android google-maps android-maps-v2

10
推荐指数
1
解决办法
1万
查看次数

在Android项目中使用'compileOnly'范围?

我在我的项目中使用Gradle 2.12(或更新版本)和适当版本的Android Gradle插件.Gradle 2.12引入了  compileOnly配置,为什么我尝试使用它时会出现错误?

无法为参数找到方法compileOnly()

gradle android-gradle-plugin

10
推荐指数
2
解决办法
3923
查看次数