I am using github.com/apple/swift-protobuf tag 0.9.904 and github.com/grpc/grpc-swift tag 0.1.12 with Xcode in my iOS app. I am also using the same versions with protoc to compile my .proto file.
The app works fine in the iOS simulator but when I try to run the app on my device I get compile errors on the following bit of generated code in myapp.pb.swift:
// If the compiler emits an error on this type, it is because this file
// was generated by a version of the `protoc` Swift plug-in that is
// incompatible with the version of SwiftProtobuf to which you are linking.
// Please ensure that your are building against the same version of the API
// that was used to generate this file.
fileprivate struct _GeneratedWithProtocGenSwiftVersion: SwiftProtobuf.ProtobufAPIVersionCheck {
struct _2: SwiftProtobuf.ProtobufAPIVersion_2 {}
typealias Version = _2
}
The errors are
No type named 'ProtobufAPIVersion_2' in module 'SwiftProtobuf'
and
Type '_GeneratedWithProtocGenSwiftVersion' does not conform to protocol 'ProtobufAPIVersionCheck'
The comment on the piece of code causing the errors speaks for itself. However, if this is true, why does the app compile and run fine in the simulator? How can I get it to compile and run on my device as well?
If this is still a problem for you, please file a GitHub issue on the swift-protobuf project.
Related
We are building an app using Catalyst and I need to run UI tests on both iOS and macOS. However, in the iOS/iPadOS there are gestures (swipes, long press etc.), which are not present on macOS. So, when I try to build tests on macOS, it fails with the errors like "Value of type 'XCUIApplication' has no member 'swipeDown'".
Does anyone have any ideas about what to do to keep one set of tests for both macOS and iOS?
Thanks in advance.
Swipes are unavailable for macOS, because macOS doesn’t run on touchscreen devices.
You can still reuse your code if you separate elements, steps and tests code with ScreenObject (aka PageObject) pattern.
Search the internet for more documentation. You can also check out my implementation of this pattern here
https://github.com/rzakhar/xctest-assignment
Your steps can be multiplatform if you use #available or #if APIs
#if os(iOS)
cell.swipeLeft()
cell.buttons["Delete"].tap()
#else
cell.buttons["More"].click()
cell.buttons["Delete"].click()
#endif
There's a similar question that works on Objective-C, but I tried the same code in Swift and it never executes, neither in the main app, nor in the action extension.
My situation is similar to the one in the question above, that is, when running from the main app I want to use UIApplication.shared.open to open a link in Safari, but I want to ignore this part of the code on the App Extension.
The problem isn't finding out whether the app is running from an App Extension or not, but ignoring the code when building for the App Extension, so that the compiler does not give me the following error on build:
You could introduce a new Custom Flag (similar to the DEBUG flag) for the extension target. In your Build Settings look for the Custom Flags and add a new one (e.g. "EXTENSION"). Like here in the screenshot, but also do it for release.
In your Code you could then do something like
#if EXTENSION
// here goes code that is only compiled in the extension
#else
// here goes code that is only compiled outside the extension
#endif
Update: Please read the Apple provided documentation on App Extensions:
Some APIs Are Unavailable to App Extensions
Because of its focused role in the system, an app extension is ineligible to participate in certain activities. An app extension cannot:
Access a Application.shared object, and so cannot use any of the methods on that object
- Apple, App Extension Programming Guide
To programmatically find if the it the running extension via code it's really simple, just do this:
let bundleUrl: URL = Bundle.main.bundleURL
let bundlePathExtension: String = bundleUrl.pathExtension
let isAppex: Bool = bundlePathExtension == "appex"
// `true` when invoked inside the `Extension process`
// `false` when invoked inside the `Main process`
My app is throwing an IllegalAccessError after updating to the latest Android Things
preview. I have the following code to check for an OTA update:
UpdateManager manager = new UpdateManager();
manager.performUpdateNow(UpdateManager.POLICY_CHECKS_ONLY);
When I run this code I get the following error output:
java.lang.IllegalAccessError: Method 'void com.google.android.things.update.UpdateManager.<init>()' is inaccessible to class 'com.example.android.things.screensettings.MainActivity' (...)
This code was working before, why has this started happening after the update?
Starting in Preview 7, Android Things API services are not constructed as new
instances. They are instead accessed as singletons via getInstance() to be
more in line with Android API paradigms.
Be sure to update your app to use the Preview 7 SDK:
dependencies {
compileOnly 'com.google.android.things:androidthings:0.7-devpreview'
}
Then modify your code to use getInstance() instead:
UpdateManager manager = UpdateManager.getInstance();
manager.performUpdateNow(UpdateManager.POLICY_CHECKS_ONLY);
Review the Android Things API reference
to verify if any of the other APIs you are calling have changed.
According to Apple's documentaion, I should be able to launch an app based on its bundle ID using the code below.
// Open safariapp
let safariApp = XCUIApplication(bundleIdentifier: "com.apple.mobilesafari")
// Launch safari app
safariApp.launch()
Unfortunately, this code will not compile because Xcode claims that XCUIApplication can not take any initialization arguments. This is my error:
Argument passed to call that takes no arguments
This functionality is available starting with the Xcode 9 SDK, so you'll need to update your Xcode version and migrate to Swift 3.2 or 4.
Source: https://developer.apple.com/documentation/xctest/xcuiapplication/2879415-init
Background
I have a fairly detailed (around 2000 lines of swift code) automation framework built with Xcode 7.3 and Swift for our iOS app.
Up till a recent point, I was able to use lldb to build my framework i.e
insert breakpoint and run code up till that point
use po XCUIApplication().debugDescription and expr bla bla to build the logic
repeat
Problem
Pretty much all of a sudden, I now encounter the following error whenever running anything inside lldb's console:
(lldb) po XCUIApplication()
error: <EXPR>:2:1: error: 'XCUIApplication' is only available on iOS 9.0 or newer
XCUIApplication()
^
<EXPR>:2:1: note: add 'if #available' version check
XCUIApplication()
^
<EXPR>:2:1: note: add #available attribute to enclosing instance method
XCUIApplication()
^
<EXPR>:2:1: note: add #available attribute to enclosing extension
XCUIApplication()
^
<EXPR>:10:9: warning: initialization of variable '$__lldb_error_result' was never used; consider replacing with assignment to '_' or removing it
var $__lldb_error_result = __lldb_tmp_error
~~~~^~~~~~~~~~~~~~~~~~~~
Notes
Googling and research has not gotten me anywhere significant.
The one relevant thread I found was in the fastlane project. Unlike that comment, mine is a UI Test target.
Also, the test target's "iOS Deployment Target" is set to iOS 9.2 (in case that helps).
To the extent I remember, I haven't changed anything significantly in recent times.
My device is (and has always been) iOS 9+.
What could be going wrong?
Update 20 May 2016
Some exploration based on the answer below: https://stackoverflow.com/a/37335950/682912
The issue happens only on real devices. Simulators do not face this problem.
On real device (iPhone 6S+, iOS 9.2.1), I did a full reset of Content and Settings. This did not fix the issue.
This is a bug in the debug agent installed on your device. These are bound to the iOS version, so it probably happened when you upgraded your device. Anyway, please file a bug with http://bugreporter.apple.com.
If I'm right about the problem, it should only happen when debugging to the device, not on the simulator. That might allow you a temporary workaround till the bug gets fixed.
Double check your .xcconfig with your test target or any other means that may set your IPHONEOS_DEPLOYMENT_TARGET to lower than 9.0.
Since UITest is only available on iOS9.0 or later, change IPHONEOS_DEPLOYMENT_TARGET to 9.0+ should fix the issue.